CFx SDK Documentation  2022 SP0
FMSliceContourBuilder.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2015, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2015 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 #ifndef FMSLICECONTOURBUILDER_H_INCLUDED
24 #define FMSLICECONTOURBUILDER_H_INCLUDED
25 
26 #include "FMProfile3D.h"
27 #include "FMGeometry.h"
28 #include "FMGeometryDebug.h"
29 #include "Contours/FMEdgeGraph.h"
30 
31 #include "Ge/GePlane.h"
32 #include "Ge/GeLineSeg3d.h"
33 #include <UInt32Array.h>
34 #include "Si/SiSpatialIndex.h"
35 #include "Si/SiShapePlane.h"
36 #include "Ge/GeLine3d.h"
37 #include "FMDebugDraw.h"
38 
39 namespace FacetModeler
40 {
42  // special container type used to keep sequenced data, but has ability fast search for value
44  template<typename T>
45  class TListSet
46  {
47  std::list<T> m_lstValues; // keeps sequence
48  std::set<T> m_setValues; // used for fast search
49 
50  public:
51  TListSet() {};
52  ~TListSet() {};
53 
54  const std::list<T>& get_list() const
55  {
56  return m_lstValues;
57  }
58 
59  const T& front() const
60  {
61  return m_lstValues.front();
62  }
63 
64  const T& back() const
65  {
66  return m_lstValues.back();
67  }
68 
69  void push_back(const T& aVal)
70  {
71  m_lstValues.push_back(aVal);
72  m_setValues.insert(aVal);
73  }
74 
75  size_t size() const
76  {
77  return m_lstValues.size();
78  }
79 
80  void clear()
81  {
82  m_lstValues.clear();
83  m_setValues.clear();
84  }
85 
86  void pop_back()
87  {
88  if(size() == 0)
89  return;
90 
91  const T& aVal = m_lstValues.back();
92  m_setValues.erase(aVal);
93  m_lstValues.pop_back();
94  }
95 
96  bool has_value(const T& aVal) const
97  {
98  return (m_setValues.find(aVal) != m_setValues.end());
99  }
100 
101  bool is_equal(const TListSet<T>& t2) const
102  {
103  return (m_lstValues == t2.m_lstValues);
104  }
105  };
106 
108  // A sequence of edges indices in EdgeGraph object. The sequence represents closed contour of graph edges
111  {
112  TListSet<OdUInt32> aContour;
113  OdUInt32 m_hash;
114 
115  public:
116  typedef std::list<OdUInt32> TContour;
117 
118  public:
119  SliceContour() : m_hash(0) {};
121 
122  OdUInt32 GetHash() const;
123 
124  const TContour& GetContour() const;
125  void AddEdge(OdUInt32 iEdge);
126 
129 
130  size_t Size() const;
131  void Clear();
132 
134 
135  bool HasEdge(OdUInt32 iEdge) const;
136 
137  friend bool operator == (const SliceContour& c1, const SliceContour& c2);
138  };
139 
140  bool operator == (const SliceContour& c1, const SliceContour& c2);
141 
142 
144  // A map of SliceContours sorted by it's hash key value. This is used for
145  // storing SliceContours and not let the container to have contours duplicates
147  typedef std::multimap<OdUInt32, SliceContour> SliceContoursMap;
148 
150  {
151  SliceContoursMap m_slices;
152 
153  public:
154  bool AddContour(const SliceContour& aContour);
155  bool HasContour( const SliceContour& aContour ) const;
156 
157  SliceContoursMap& GetContours() { return m_slices; }
158  const SliceContoursMap& GetContours() const { return m_slices; }
159  };
160 
162  // Encapsulates algorithm for building slice contours, based on EdgeGraph
164  //typedef std::vector<AECGe::Contour2D> ContoursVector;
166  typedef std::vector<OdUInt32> SliceNodes;
167 
168  class EdgeGraph2d;
169 
170  class FMGEOMETRY_API SliceContourBuilder
171  {
172  EdgeGraph& m_graph;
173 
174  typedef std::set<OdUInt32> AssignedEdges;
175  AssignedEdges m_assignedEdges;
176 
177  double m_extLeft;
178  double m_extRight;
179  double m_extTop;
180  double m_extBottom;
181 
182  public:
184 
185  private:
186  bool IsEdgeAssigned(OdUInt32 edgeIdx) { return m_assignedEdges.find(edgeIdx) != m_assignedEdges.end(); }
187  void SetEdgeAssigned(OdUInt32 edgeIdx) { m_assignedEdges.insert(edgeIdx); }
188 
189  void InitializeExtents(const OdGePlane& rCutPlane, const SliceContoursMap& aSlices);
190  void AddPoint2dToExtents(const OdGePoint2d& ptVertex2d);
191  void RemoveOverlappingContours( ContoursVector& rContours2d );
192 
193  private:
194  bool RecursiveFindCycle( SliceContour& aContour, SliceContourCollection& aSlices );
195  void MarkDuplicatedEdges();
196  void SplitSliceToContours2d( const OdGePlane& rCutPlane, const SliceContourCollection& aSliceContours, ContoursVector& rContours2d );
197 
198  SliceNodes GetSliceContourNodes( const SliceContour& aSlice, OdArray<const Edge*>* aTag = NULL);
199  void MakeClosedContour( Contour2D& rResult );
200  void MakeClosedContour2dFromSliceNodes( const OdGePlane& rCutPlane, const SliceNodes& rSliceNodes, Contour2D& rResult, const OdArray<const Edge*>& aTag);
201 
202  void AddSurfacesToProfile( const ContoursVector& rContours2d, Profile2D& rResult );
203  void CutHolesFromProfile( const ContoursVector& rContours2d, Profile2D& rResult );
204  void BuildResultProfile( ContoursVector& rContours2d, Profile2D& rResult );
205 
206  public:
207  SliceContourBuilder(EdgeGraph& aGraph) : m_graph (aGraph), m_sourceEdges(NULL)
208  {
209  m_extLeft = 0.0;
210  m_extRight = 0.0;
211  m_extTop = 0.0;
212  m_extBottom = 0.0;
213  };
215 
216  bool IsContourClosed( const SliceContour& aContour );
217 
218  bool FindContour( std::vector<OdUInt32>& aContour );
219 
220  void FindSliceContours( SliceContourCollection& aSliceContours );
221 
222  public:
223  void BuildSliceProfile( const OdGePlane& rCutPlane, Profile2D& rResult );
224 
225  private:
226  OdGePlane m_cutPlane;
227 
228  public:
229  void BuildSliceProfile2( const OdGePlane& rCutPlane, Profile2D& rResult );
230 
231  private:
232  void FindSliceContours2( SliceContourCollection& aSliceContours ) ;
233 
234 
235  private:
236  // DEBUG FUNCTIONS
237  typedef std::vector<SliceEdge> Edges;
238 
239  void DebugDrawEdgeGraph();
240  void DebugDrawEdge(OdUInt32 uEdgeIdx, Edges& drawnEdges, OdInt16 edgeBaseColor = 0);
241  void DebugDrawEdge(OdUInt32 uEdgeIdx, OdInt16 edgeBaseColor = 0);
242  bool HasCoincidentEdge(OdUInt32 uEdgeIdx, const Edges& drawnEdges);
243  bool HasCoincidentOppositeEdge(OdUInt32 uEdgeIdx, const Edges& drawnEdges);
244  void DebugDrawSliceContour(SliceContour& contour);
245  void DebugDrawSliceContourCollection(SliceContourCollection& contoursColl);
246  void DebugCheckForDuplicatedNodes();
247  };
248 }
249 
250 #endif //FMSLICECONTOURBUILDER_H_INCLUDED
#define NULL
Definition: GsProperties.h:177
unsigned int OdUInt32
short OdInt16
void FindSliceContours(SliceContourCollection &aSliceContours)
void BuildSliceProfile2(const OdGePlane &rCutPlane, Profile2D &rResult)
bool FindContour(std::vector< OdUInt32 > &aContour)
bool IsContourClosed(const SliceContour &aContour)
void BuildSliceProfile(const OdGePlane &rCutPlane, Profile2D &rResult)
OdArray< const Edge * > * m_sourceEdges
bool HasContour(const SliceContour &aContour) const
const SliceContoursMap & GetContours() const
bool AddContour(const SliceContour &aContour)
friend bool operator==(const SliceContour &c1, const SliceContour &c2)
OdUInt32 GetFirstEdge() const
const TContour & GetContour() const
OdUInt32 GetHash() const
std::list< OdUInt32 > TContour
OdUInt32 GetLastEdge() const
void AddEdge(OdUInt32 iEdge)
bool HasEdge(OdUInt32 iEdge) const
bool is_equal(const TListSet< T > &t2) const
bool has_value(const T &aVal) const
const std::list< T > & get_list() const
void push_back(const T &aVal)
std::vector< OdUInt32 > SliceNodes
std::multimap< OdUInt32, SliceContour > SliceContoursMap