ArcGIS Procedural Runtime  3.2.10650
EncodePreparator.h
1 /*
2  COPYRIGHT (c) 2012-2024 Esri R&D Center Zurich
3  TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
4  Unpublished material - all rights reserved under the
5  Copyright Laws of the United States and applicable international
6  laws, treaties, and conventions.
7 
8  For additional information, contact:
9  Environmental Systems Research Institute, Inc.
10  Attn: Contracts and Legal Services Department
11  380 New York Street
12  Redlands, California, 92373
13  USA
14 
15  email: contracts@esri.com
16 */
17 
18 #ifndef PRTX_ENCODEPREPARATOR_H_
19 #define PRTX_ENCODEPREPARATOR_H_
20 
21 #include "prt/Callbacks.h"
22 
23 #include "prtx/NamePreparator.h"
24 #include "prtx/Shape.h"
25 #include "prtx/prtx.h"
26 
27 #ifdef _MSC_VER
28 # pragma warning(push)
29 # pragma warning(disable : 4275 4251)
30 #endif
31 
32 #include <memory>
33 
34 namespace prt {
35  class Cache;
36 }
37 
38 namespace prtx {
39 
40 class InitialShape;
41 
46 enum Action {
47  PASS,
51 };
52 };
53 
54 struct HoleProcessor {
58 enum Action {
59  PASS,
63 };
64 };
65 
66 struct MeshMerging {
71 enum Action {
72  NONE,
75 };
76 };
77 
86  virtual void update(
87  const prt::AttributeMap* initialShapeAttributes,
88  const prtx::MaterialPtr& originalMaterial,
89  prtx::MaterialBuilder& materialUpdate
90  ) const = 0;
91 };
92 
93 
94 class Reports;
95 typedef std::shared_ptr<Reports> ReportsPtr;
96 
100 class PRTX_EXPORTS_API Reports {
101 public:
102  Reports() { }
103  Reports(
104  const prtx::Shape::ReportBoolVect& boolReps,
105  const prtx::Shape::ReportFloatVect& floatReps,
106  const prtx::Shape::ReportStringVect& stringReps
107  );
108 
112  void append(const ReportsPtr& r);
113 
114  prtx::Shape::ReportBoolVect mBools;
115  prtx::Shape::ReportFloatVect mFloats;
116  prtx::Shape::ReportStringVect mStrings;
117 };
118 
119 
120 class EncodePreparator;
121 typedef std::shared_ptr<EncodePreparator> EncodePreparatorPtr;
122 
123 
162 class PRTX_EXPORTS_API EncodePreparator {
163 public:
164  static const prtx::DoubleVector IDENTITY;
165  class FinalizedInstance;
166  typedef std::vector<FinalizedInstance> InstanceVector;
167  class PreparationFlags;
168 
169 public:
184  static EncodePreparatorPtr create(
185  bool enforceTextureConsistency,
186  NamePreparator& namePreparator,
187  const NamePreparator::NamespacePtr& nsMeshes,
188  const NamePreparator::NamespacePtr& nsMaterials,
189  const MaterialTransformer* materialTransformer = 0
190  );
191 
205  virtual void add(
206  prt::Cache* cache,
207  const ShapePtr& shape,
208  const prt::AttributeMap* initialShapeAttributes,
209  const ReportsPtr& reports = ReportsPtr()
210  ) = 0;
211 
223  virtual void add(
224  prt::Cache* cache,
225  const prtx::InitialShape& initialShape,
226  size_t initialShapeIndex
227  ) = 0;
228 
236  static uint32_t getInitialShapePseudoShapeId(size_t initialShapeIndex);
237 
253  virtual void fetchFinalizedInstances(
254  InstanceVector& instances,
255  const PreparationFlags& flags,
256  prt::SimpleOutputCallbacks* cbForLogStats = nullptr
257  ) = 0;
258 
265  virtual void getBoundingBox(prtx::BoundingBox& bbox) = 0;
266 
270  virtual uint64_t getUsedMem(bool considerInstanceCounts = false) const = 0;
271 
275  virtual void clear() = 0;
276 
277  virtual ~EncodePreparator();
278 
279 protected:
281  GeometryPtr mGeometry;
282  prtx::DoubleVector mTransformation;
283  prtx::MaterialPtrVector mMaterials;
284  StringPtr mInitialShapeName;
285  StringPtr mShapeName;
286  uint32_t mInitialShapeIndex;
287  uint32_t mShapeId;
288  std::vector<uint32_t> mMeshProperties;
289  int32_t mPrototype;
290  ReportsPtr mReports;
291  };
292 
294  EncodePreparator(const EncodePreparator&) = delete;
295  EncodePreparator& operator=(const EncodePreparator&) = delete;
296 
297  static FinalizedInstanceBase& getBase(FinalizedInstance& instance);
298 
299 public:
306  ALL_MESH_FACES_CONVEX = 1 << 0,
307  ALL_MESH_FACES_PLANAR = 1 << 1
308  };
309 
313  class PRTX_EXPORTS_API FinalizedInstance : private FinalizedInstanceBase {
314  public:
315  static const uint32_t NO_INITIAL_SHAPE_INDEX = uint32_t(-1);
316  static const uint32_t NO_SHAPE_ID = uint32_t(-1);
317  static const int32_t NO_PROTOTYPE_INDEX = -1;
318 
319  public:
324  const GeometryPtr& getGeometry() const;
325 
329  const prtx::DoubleVector& getTransformation() const;
330 
343  const prtx::MaterialPtrVector& getMaterials() const;
344 
349  const std::wstring& getInitialShapeName() const;
350 
354  const std::wstring& getShapeName() const;
355 
359  uint32_t getInitialShapeIndex() const;
360 
364  uint32_t getShapeId() const;
365 
372  int32_t getPrototypeIndex() const;
373 
380  bool allMeshFacesConvex(size_t meshIndex) const;
381 
388  bool allMeshFacesPlanar(size_t meshIndex) const;
389 
393  const ReportsPtr& getReports() const;
394 
395  private:
396  FinalizedInstanceBase& getBase();
397  friend class EncodePreparator;
398  };
399 
406  class PRTX_EXPORTS_API PreparationFlags {
407  public:
415  INDICES_SEPARATE_FOR_ALL_VERTEX_ATTRIBUTES = 0,
416 
420  INDICES_SAME_FOR_VERTICES_AND_NORMALS = (1 << 0),
421 
425  INDICES_SAME_FOR_VERTICES_AND_FIRST_UV_SET = (1 << 1),
426 
430  INDICES_SAME_FOR_VERTICES_AND_ALL_UV_SETS = (1 << 2) | INDICES_SAME_FOR_VERTICES_AND_FIRST_UV_SET,
431 
435  INDICES_SAME_FOR_VERTICES_AND_NORMALS_AND_FIRST_UV_SET = INDICES_SAME_FOR_VERTICES_AND_NORMALS | INDICES_SAME_FOR_VERTICES_AND_FIRST_UV_SET,
436 
440  INDICES_SAME_FOR_ALL_VERTEX_ATTRIBUTES = INDICES_SAME_FOR_VERTICES_AND_NORMALS | INDICES_SAME_FOR_VERTICES_AND_ALL_UV_SETS
441  };
442 
443  public:
445 
449  PreparationFlags& instancing(bool v);
450 
454  [[deprecated("replaced by meshMerging")]] PreparationFlags& mergeByMaterial(bool v);
455 
459  PreparationFlags& meshMerging(MeshMerging::Action v);
460 
465  PreparationFlags& cutoutTextures(bool v);
466 
470  PreparationFlags& createTextureAtlases(bool v);
471 
475  PreparationFlags& atlasRepeatingTextures(bool v);
476 
480  PreparationFlags& maxAtlasDim(int v);
481 
485  PreparationFlags& atlasAddWrapBorder(bool v);
486 
490  PreparationFlags& forceAtlasing(bool v);
491 
495  PreparationFlags& maxTexSize(uint32_t v);
496 
500  PreparationFlags& triangulate(bool v);
501 
505  PreparationFlags& offset(double x, double y, double z);
506 
510  PreparationFlags& offset(const double* xyz);
511 
517  PreparationFlags& processVertexNormals(VertexNormalProcessor::Action v);
518 
524  PreparationFlags& processHoles(HoleProcessor::Action v);
525 
530  PreparationFlags& mergeVertices(bool v);
531 
535  PreparationFlags& cleanupVertexNormals(bool v);
536 
540  PreparationFlags& cleanupUVs(bool v);
541 
545  PreparationFlags& mergeToleranceVertices(float v);
546 
550  PreparationFlags& mergeToleranceNormals(float v);
551 
555  PreparationFlags& mergeToleranceUVs(float v);
556 
562  PreparationFlags& indexSharing(IndexSharing v);
563 
568  PreparationFlags& determineMeshProperties(bool v);
569 
570  bool instancing() const;
571  [[deprecated("replaced by meshMerging")]] bool mergeByMaterial() const;
572  MeshMerging::Action meshMerging() const;
573  bool cutoutTextures() const;
574  bool createTextureAtlases() const;
575  bool atlasRepeatingTextures() const;
576  int maxAtlasDim() const;
577  bool atlasAddWrapBorder() const;
578  bool forceAtlasing() const;
579  uint32_t maxTexSize() const;
580  bool triangulate() const;
581  const double* offset() const;
582  VertexNormalProcessor::Action processVertexNormals() const;
583  HoleProcessor::Action processHoles() const;
584  bool mergeVertices() const;
585  bool cleanupVertexNormals() const;
586  bool cleanupUVs() const;
587  float mergeToleranceVertices() const;
588  float mergeToleranceNormals() const;
589  float mergeToleranceUVs() const;
590  IndexSharing indexSharing() const;
591  bool determineMeshProperties() const;
592 
593  private:
594  bool mInstancing;
595  MeshMerging::Action mMeshMerging;
596  bool mCutoutTextures;
597  bool mCreateTextureAtlases;
598  bool mAtlasRepeatingTextures;
599  int mMaxAtlasDim;
600  bool mAtlasAddWrapBorder;
601  bool mForceAtlasing;
602  uint32_t mMaxTexSize;
603  bool mTriangulate;
604  bool mDetermineMeshProperties;
605  bool mMergeVertices;
606  bool mCleanupVertexNormals;
607  bool mCleanupUVs;
608  VertexNormalProcessor::Action mVertexNormalAction;
609  HoleProcessor::Action mHoleAction;
610  IndexSharing mIndexSharing;
611  float mMergeToleranceVertices;
612  float mMergeToleranceNormals;
613  float mMergeToleranceUVs;
614  double mOffset[3];
615  };
616 };
617 
618 
619 } // namespace prtx
620 
621 
622 #ifdef _MSC_VER
623 # pragma warning(pop)
624 #endif
625 
626 
627 #endif /* PRTX_ENCODEPREPARATOR_H_ */
Any missing vertex normals will be set to the corresponding face normal.
Definition: EncodePreparator.h:49
Faces with holes are not modified.
Definition: EncodePreparator.h:59
Non-instanced meshes of the same type and with identical material attributes are merged together...
Definition: EncodePreparator.h:73
Definition: BoundingBox.h:38
All non-instanced meshes of the same type are merged together.
Definition: EncodePreparator.h:74
Faces with holes will be triangulated.
Definition: EncodePreparator.h:60
std::vector< double > DoubleVector
vector of double
Definition: Types.h:32
Holes will be converted to regular faces.
Definition: EncodePreparator.h:62
std::shared_ptr< Material > MaterialPtr
shared Material pointer
Definition: DataBackend.h:45
Any holes will be deleted.
Definition: EncodePreparator.h:61
IndexSharing
Definition: EncodePreparator.h:411
Action
Definition: EncodePreparator.h:46
std::shared_ptr< std::wstring > StringPtr
shared std::string
Definition: Types.h:36
Definition: EncodePreparator.h:313
Meshes are not merged.
Definition: EncodePreparator.h:72
Action
Definition: EncodePreparator.h:71
Definition: EncodePreparator.h:162
The Procedural Runtime eXtension namespace. The prtx namespace contains the tools to extend the Proce...
Definition: AnnotationBuilder.h:35
Definition: EncodePreparator.h:280
Definition: /InitialShape.h:29
Definition: EncodePreparator.h:66
std::shared_ptr< Geometry > GeometryPtr
shared Geometry pointer
Definition: DebugUtils.h:37
Definition: Callbacks.h:270
Definition: Cache.h:53
std::vector< MaterialPtr > MaterialPtrVector
vector of shared Material pointers
Definition: DataBackend.h:46
All vertex normals will be replaced with the corresponding face normal.
Definition: EncodePreparator.h:50
The vertex normals are not modified.
Definition: EncodePreparator.h:47
std::shared_ptr< Shape > ShapePtr
shared pointer to a Shape
Definition: Shape.h:41
Definition: AttributeMap.h:32
Action
Definition: EncodePreparator.h:58
Definition: EncodePreparator.h:85
Definition: EncodePreparator.h:406
Definition: EncodePreparator.h:42
Definition: EncodePreparator.h:54
Definition: EncodePreparator.h:100
The Procedural Runtime API namespace. The prt namespace contains the top level entry points into the ...
Definition: Annotation.h:24
The vertex normals are deleted.
Definition: EncodePreparator.h:48
MeshProperties
Definition: EncodePreparator.h:305
Definition: Material.h:306