ArcGIS Procedural Runtime  3.5.12540
EncodePreparator.h
1 /*
2  COPYRIGHT (c) 2012-2026 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 
78 struct Instancing {
86 enum Action {
87  NONE,
88  ALL,
90 };
92 };
93 
102  virtual void update(
103  const prt::AttributeMap* initialShapeAttributes,
104  const prtx::MaterialPtr& originalMaterial,
105  prtx::MaterialBuilder& materialUpdate
106  ) const = 0;
107 };
108 
109 
110 class Reports;
111 typedef std::shared_ptr<Reports> ReportsPtr;
112 
116 class PRTX_EXPORTS_API Reports {
117 public:
118  Reports() { }
119  Reports(
120  const prtx::Shape::ReportBoolVect& boolReps,
121  const prtx::Shape::ReportFloatVect& floatReps,
122  const prtx::Shape::ReportStringVect& stringReps
123  );
124 
128  void append(const ReportsPtr& r);
129 
130  prtx::Shape::ReportBoolVect mBools;
131  prtx::Shape::ReportFloatVect mFloats;
132  prtx::Shape::ReportStringVect mStrings;
133 };
134 
135 
136 class EncodePreparator;
137 typedef std::shared_ptr<EncodePreparator> EncodePreparatorPtr;
138 
139 
178 class PRTX_EXPORTS_API EncodePreparator {
179 public:
180  static const prtx::DoubleVector IDENTITY;
183  typedef std::vector<FinalizedInstance> InstanceVector;
184  class PreparationFlags;
185 
186 public:
201  static EncodePreparatorPtr create(
202  bool enforceTextureConsistency,
203  NamePreparator& namePreparator,
204  const NamePreparator::NamespacePtr& nsMeshes,
205  const NamePreparator::NamespacePtr& nsMaterials,
206  const MaterialTransformer* materialTransformer = 0
207  );
208 
222  virtual void add(
223  prt::Cache* cache,
224  const ShapePtr& shape,
225  const prt::AttributeMap* initialShapeAttributes,
226  const ReportsPtr& reports = ReportsPtr()
227  ) = 0;
228 
240  virtual void add(
241  prt::Cache* cache,
242  const prtx::InitialShape& initialShape,
243  size_t initialShapeIndex
244  ) = 0;
245 
253  static uint32_t getInitialShapePseudoShapeId(size_t initialShapeIndex);
254 
270  virtual void fetchFinalizedInstances(
271  InstanceVector& instances,
272  const PreparationFlags& flags,
273  prt::SimpleOutputCallbacks* cbForLogStats = nullptr
274  ) = 0;
275 
282  virtual void getBoundingBox(prtx::BoundingBox& bbox) = 0;
283 
287  virtual uint64_t getUsedMem(bool considerInstanceCounts = false) const = 0;
288 
292  virtual void clear() = 0;
293 
294  virtual ~EncodePreparator();
295 
296 protected:
298  GeometryPtr mGeometry;
299  prtx::DoubleVector mTransformation;
300  prtx::MaterialPtrVector mMaterials;
301  StringPtr mInitialShapeName;
302  StringPtr mShapeName;
303  uint32_t mInitialShapeIndex;
304  uint32_t mShapeId;
305  std::vector<uint32_t> mMeshProperties;
306  int32_t mPrototype;
307  ReportsPtr mReports;
308  };
309 
311  EncodePreparator(const EncodePreparator&) = delete;
312  EncodePreparator& operator=(const EncodePreparator&) = delete;
313 
314  static FinalizedInstanceBase& getBase(FinalizedInstance& instance);
315 
316 public:
323  ALL_MESH_FACES_CONVEX = 1 << 0,
324  ALL_MESH_FACES_PLANAR = 1 << 1
325  };
326 
330  class PRTX_EXPORTS_API FinalizedInstance : private FinalizedInstanceBase {
331  public:
332  static const uint32_t NO_INITIAL_SHAPE_INDEX = uint32_t(-1);
333  static const uint32_t NO_SHAPE_ID = uint32_t(-1);
334  static const int32_t NO_PROTOTYPE_INDEX = -1;
335 
336  public:
341  const GeometryPtr& getGeometry() const;
342 
346  const prtx::DoubleVector& getTransformation() const;
347 
360  const prtx::MaterialPtrVector& getMaterials() const;
361 
366  const std::wstring& getInitialShapeName() const;
367 
371  const std::wstring& getShapeName() const;
372 
376  uint32_t getInitialShapeIndex() const;
377 
381  uint32_t getShapeId() const;
382 
389  int32_t getPrototypeIndex() const;
390 
397  bool allMeshFacesConvex(size_t meshIndex) const;
398 
405  bool allMeshFacesPlanar(size_t meshIndex) const;
406 
410  const ReportsPtr& getReports() const;
411 
412  private:
413  FinalizedInstanceBase& getBase();
414  friend class EncodePreparator;
415  };
416 
447  class PRTX_EXPORTS_API PreparationFlags {
448  public:
456  INDICES_SEPARATE_FOR_ALL_VERTEX_ATTRIBUTES = 0,
457 
461  INDICES_SAME_FOR_VERTICES_AND_NORMALS = (1 << 0),
462 
466  INDICES_SAME_FOR_VERTICES_AND_FIRST_UV_SET = (1 << 1),
467 
471  INDICES_SAME_FOR_VERTICES_AND_ALL_UV_SETS = (1 << 2) | INDICES_SAME_FOR_VERTICES_AND_FIRST_UV_SET,
472 
476  INDICES_SAME_FOR_VERTICES_AND_NORMALS_AND_FIRST_UV_SET = INDICES_SAME_FOR_VERTICES_AND_NORMALS | INDICES_SAME_FOR_VERTICES_AND_FIRST_UV_SET,
477 
481  INDICES_SAME_FOR_ALL_VERTEX_ATTRIBUTES = INDICES_SAME_FOR_VERTICES_AND_NORMALS | INDICES_SAME_FOR_VERTICES_AND_ALL_UV_SETS
482  };
483 
484  public:
486 
491  [[deprecated("replaced by instancingMode")]] PreparationFlags& instancing(bool v);
492 
496  PreparationFlags& instancingMode(Instancing::Action v);
497 
501  [[deprecated("replaced by meshMerging")]] PreparationFlags& mergeByMaterial(bool v);
502 
506  PreparationFlags& meshMerging(MeshMerging::Action v);
507 
512  PreparationFlags& cutoutTextures(bool v);
513 
517  PreparationFlags& createTextureAtlases(bool v);
518 
522  PreparationFlags& atlasRepeatingTextures(bool v);
523 
527  PreparationFlags& maxAtlasDim(int v);
528 
532  PreparationFlags& atlasAddWrapBorder(bool v);
533 
537  PreparationFlags& forceAtlasing(bool v);
538 
542  PreparationFlags& maxTexSize(uint32_t v);
543 
547  PreparationFlags& triangulate(bool v);
548 
552  PreparationFlags& offset(double x, double y, double z);
553 
557  PreparationFlags& offset(const double* xyz);
558 
564  PreparationFlags& processVertexNormals(VertexNormalProcessor::Action v);
565 
571  PreparationFlags& processHoles(HoleProcessor::Action v);
572 
577  PreparationFlags& mergeVertices(bool v);
578 
582  PreparationFlags& cleanupVertexNormals(bool v);
583 
587  PreparationFlags& cleanupUVs(bool v);
588 
592  PreparationFlags& mergeToleranceVertices(float v);
593 
597  PreparationFlags& mergeToleranceNormals(float v);
598 
602  PreparationFlags& mergeToleranceUVs(float v);
603 
609  PreparationFlags& indexSharing(IndexSharing v);
610 
615  PreparationFlags& determineMeshProperties(bool v);
616 
621  PreparationFlags& bakeTextureTrafos(bool v);
622 
623  [[deprecated("replaced by instancingMode")]] bool instancing() const;
624  Instancing::Action instancingMode() const;
625  [[deprecated("replaced by meshMerging")]] bool mergeByMaterial() const;
626  MeshMerging::Action meshMerging() const;
627  bool cutoutTextures() const;
628  bool createTextureAtlases() const;
629  bool atlasRepeatingTextures() const;
630  int maxAtlasDim() const;
631  bool atlasAddWrapBorder() const;
632  bool forceAtlasing() const;
633  uint32_t maxTexSize() const;
634  bool triangulate() const;
635  const double* offset() const;
636  VertexNormalProcessor::Action processVertexNormals() const;
637  HoleProcessor::Action processHoles() const;
638  bool mergeVertices() const;
639  bool cleanupVertexNormals() const;
640  bool cleanupUVs() const;
641  float mergeToleranceVertices() const;
642  float mergeToleranceNormals() const;
643  float mergeToleranceUVs() const;
644  IndexSharing indexSharing() const;
645  bool determineMeshProperties() const;
646  bool bakeTextureTrafos() const;
647 
648  private:
649  Instancing::Action mInstancing;
650  MeshMerging::Action mMeshMerging;
651  bool mCutoutTextures;
652  bool mCreateTextureAtlases;
653  bool mAtlasRepeatingTextures;
654  int mMaxAtlasDim;
655  bool mAtlasAddWrapBorder;
656  bool mForceAtlasing;
657  uint32_t mMaxTexSize;
658  bool mTriangulate;
659  bool mDetermineMeshProperties;
660  bool mMergeVertices;
661  bool mCleanupVertexNormals;
662  bool mCleanupUVs;
663  VertexNormalProcessor::Action mVertexNormalAction;
664  HoleProcessor::Action mHoleAction;
665  IndexSharing mIndexSharing;
666  float mMergeToleranceVertices;
667  float mMergeToleranceNormals;
668  float mMergeToleranceUVs;
669  double mOffset[3];
670  bool mBakeTextureTrafos;
671  };
672 };
673 
674 
675 } // namespace prtx
676 
677 
678 #ifdef _MSC_VER
679 # pragma warning(pop)
680 #endif
681 
682 
683 #endif /* PRTX_ENCODEPREPARATOR_H_ */
Any missing vertex normals will be set to the corresponding face normal.
Definition: EncodePreparator.h:49
Definition: EncodePreparator.h:78
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
Action
Definition: EncodePreparator.h:86
All non-instanced meshes of the same type are merged together.
Definition: EncodePreparator.h:74
No instancing.
Definition: EncodePreparator.h:87
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:452
Action
Definition: EncodePreparator.h:46
std::shared_ptr< std::wstring > StringPtr
shared std::string
Definition: Types.h:36
Definition: EncodePreparator.h:330
Meshes are not merged.
Definition: EncodePreparator.h:72
Action
Definition: EncodePreparator.h:71
Definition: EncodePreparator.h:89
Definition: EncodePreparator.h:178
The Procedural Runtime eXtension namespace. The prtx namespace contains the tools to extend the Proce...
Definition: AnnotationBuilder.h:35
Definition: EncodePreparator.h:297
Definition: /InitialShape.h:29
All cached/identical meshes are treated as instances.
Definition: EncodePreparator.h:88
Definition: EncodePreparator.h:66
std::shared_ptr< Geometry > GeometryPtr
shared Geometry pointer
Definition: DebugUtils.h:37
Definition: Callbacks.h:299
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
std::vector< FinalizedInstance > InstanceVector
Definition: EncodePreparator.h:181
Definition: EncodePreparator.h:101
Definition: EncodePreparator.h:447
Definition: EncodePreparator.h:42
Definition: EncodePreparator.h:54
Definition: EncodePreparator.h:116
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:322
Definition: Material.h:306