CEdgeLine.h
Go to the documentation of this file.
1 #ifndef iedge_CEdgeLine_included
2 #define iedge_CEdgeLine_included
3 
4 
5 // ACF includes
7 #include <i2d/CObject2dBase.h>
8 #include <i2d/CPolyline.h>
9 #include <i2d/CAffine2d.h>
10 
11 // ACF-Solutions includes
12 #include <iedge/CEdgeNode.h>
13 
14 
15 namespace iedge
16 {
17 
18 
20 {
21 public:
23 
24  CEdgeLine();
25  CEdgeLine(const CEdgeLine& edgeLine);
26 
27  void Clear();
28 
32  int GetNodesCount() const;
36  int GetSegmentsCount() const;
37 
41  void SetNodesCount(int count);
42 
47  const CEdgeNode& GetNode(int index) const;
52  CEdgeNode& GetNodeRef(int index);
53 
59  void SetNode(int index, const CEdgeNode& node);
60 
61  bool IsClosed() const;
62  void SetClosed(bool state = true);
63 
64  double GetTotalLength() const;
65  double GetMinWeight() const;
66  double GetMaxWeight() const;
67 
68  bool InsertNode(const CEdgeNode& node);
69 
77  void CopyFromPolyline(const i2d::CPolyline& polyline, double weight = 1.0, const i2d::CAffine2d* transformPtr = NULL);
84  void CopyToPolyline(i2d::CPolyline& polyline, const i2d::CAffine2d* transformPtr = NULL) const;
85 
86  // reimplemented (i2d::IObject2d)
87  virtual i2d::CVector2d GetCenter() const;
88  virtual void MoveCenterTo(const i2d::CVector2d& position);
89  virtual i2d::CRectangle GetBoundingBox() const;
90  virtual bool Transform(
91  const i2d::ITransformation2d& transformation,
92  i2d::ITransformation2d::ExactnessMode mode = i2d::ITransformation2d::EM_NONE,
93  double* errorFactorPtr = NULL);
94  virtual bool InvTransform(
95  const i2d::ITransformation2d& transformation,
96  i2d::ITransformation2d::ExactnessMode mode = i2d::ITransformation2d::EM_NONE,
97  double* errorFactorPtr = NULL);
98  virtual bool GetTransformed(
99  const i2d::ITransformation2d& transformation,
100  IObject2d& result,
101  i2d::ITransformation2d::ExactnessMode mode = i2d::ITransformation2d::EM_NONE,
102  double* errorFactorPtr = NULL) const;
103  virtual bool GetInvTransformed(
104  const i2d::ITransformation2d& transformation,
105  IObject2d& result,
106  i2d::ITransformation2d::ExactnessMode mode = i2d::ITransformation2d::EM_NONE,
107  double* errorFactorPtr = NULL) const;
108 
109  // reimplemented (iser::ISerializable)
110  virtual bool Serialize(iser::IArchive& archive);
111 
112 protected:
116  void EnsureVolatileValid() const;
117 
118  virtual void CalcVolatile() const;
119 
120  // reimplemented (istd::IChangeable)
121  virtual void OnEndChanges(const ChangeSet& changeSet);
122 
123 private:
124  // std::vector used instead of QList/QVector because it is generally faster
125  // (up to 300% for MSVC)
126  typedef std::vector<CEdgeNode> Nodes;
127 
128  Nodes m_nodes;
129 
130  bool m_isClosed;
131 
132  mutable bool m_areVolatileValid;
133  mutable double m_totalLength;
134  mutable i2d::CVector2d m_center;
135  mutable double m_minWeight;
136  mutable double m_maxWeight;
137  mutable i2d::CRectangle m_boundingBox;
138 };
139 
140 
141 // inline methods
142 
143 inline int CEdgeLine::GetNodesCount() const
144 {
145  return int(m_nodes.size());
146 }
147 
148 
149 inline int CEdgeLine::GetSegmentsCount() const
150 {
151  return m_isClosed? int(m_nodes.size()): int(m_nodes.size() - 1);
152 }
153 
154 
155 inline const CEdgeNode& CEdgeLine::GetNode(int index) const
156 {
157  return m_nodes[index];
158 }
159 
160 
162 {
163  return m_nodes[index];
164 }
165 
166 
167 inline double CEdgeLine::GetTotalLength() const
168 {
170 
171  return m_totalLength;
172 }
173 
174 
175 inline double CEdgeLine::GetMinWeight() const
176 {
178 
179  return m_minWeight;
180 }
181 
182 
183 inline double CEdgeLine::GetMaxWeight() const
184 {
186 
187  return m_maxWeight;
188 }
189 
190 
191 inline bool CEdgeLine::IsClosed() const
192 {
193  return m_isClosed;
194 }
195 
196 
197 // protected methods
198 
200 {
201  if (!m_areVolatileValid){
202  CalcVolatile();
203 
204  m_areVolatileValid = true;
205  }
206 }
207 
208 
209 } // namespace iedge
210 
211 
212 #endif // !iedge_CEdgeLine_included
213 
214 
int GetNodesCount() const
Get number of nodes.
Definition: CEdgeLine.h:143
void CopyFromPolyline(const i2d::CPolyline &polyline, double weight=1.0, const i2d::CAffine2d *transformPtr=NULL)
Create this line using polyline object.
void SetNode(int index, const CEdgeNode &node)
Set node at specified index.
virtual bool Serialize(iser::IArchive &archive)
virtual bool GetTransformed(const i2d::ITransformation2d &transformation, IObject2d &result, i2d::ITransformation2d::ExactnessMode mode=i2d::ITransformation2d::EM_NONE, double *errorFactorPtr=NULL) const
virtual i2d::CRectangle GetBoundingBox() const
CEdgeNode & GetNodeRef(int index)
Return reference to node at specified index.
Definition: CEdgeLine.h:161
virtual bool InvTransform(const i2d::ITransformation2d &transformation, i2d::ITransformation2d::ExactnessMode mode=i2d::ITransformation2d::EM_NONE, double *errorFactorPtr=NULL)
double GetTotalLength() const
Definition: CEdgeLine.h:167
virtual i2d::CVector2d GetCenter() const
virtual void OnEndChanges(const ChangeSet &changeSet)
void EnsureVolatileValid() const
Make sure, that all volatile values are calculated and valid.
Definition: CEdgeLine.h:199
virtual void MoveCenterTo(const i2d::CVector2d &position)
void SetNodesCount(int count)
Set number of nodes in container without initializing it.
double GetMaxWeight() const
Definition: CEdgeLine.h:183
i2d::CObject2dBase BaseClass
Definition: CEdgeLine.h:22
void CopyToPolyline(i2d::CPolyline &polyline, const i2d::CAffine2d *transformPtr=NULL) const
Copy this line to polyline.
int GetSegmentsCount() const
Get number of segments.
Definition: CEdgeLine.h:149
bool InsertNode(const CEdgeNode &node)
void SetClosed(bool state=true)
bool IsClosed() const
Definition: CEdgeLine.h:191
double GetMinWeight() const
Definition: CEdgeLine.h:175
const CEdgeNode & GetNode(int index) const
Return node at specified index.
Definition: CEdgeLine.h:155
Description of single node of the edge.
Definition: CEdgeNode.h:18
virtual bool GetInvTransformed(const i2d::ITransformation2d &transformation, IObject2d &result, i2d::ITransformation2d::ExactnessMode mode=i2d::ITransformation2d::EM_NONE, double *errorFactorPtr=NULL) const
virtual void CalcVolatile() const
virtual bool Transform(const i2d::ITransformation2d &transformation, i2d::ITransformation2d::ExactnessMode mode=i2d::ITransformation2d::EM_NONE, double *errorFactorPtr=NULL)

© 2007-2017 Witold Gantzke and Kirill Lepskiy