OpenWalnut  1.5.0dev
WVertexProperty.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2013 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <vector>
26 
27 #include "WVertexProperty.h"
28 
29 
31 {
32  m_boundClass = 0;
35 }
36 
38 {
39  //TODO(schwarzkopf): Memory is still not freed as it should
40  m_attachedTriangle.resize( 0 );
41  m_attachedTriangle.reserve( 0 );
42  for ( size_t index = 0; index < m_newVertices.size(); index++ )
43  {
44  m_newVertices[index]->~WNewVertex();
45  delete m_newVertices[index];
46  }
47  m_newVertices.resize( 0 );
48  m_newVertices.reserve( 0 );
49  m_stencilOnNeighbours.resize( 0 );
50  m_stencilOnNeighbours.reserve( 0 );
51 }
52 
54 {
55  return m_attachedTriangle.size();
56 }
57 
59 {
60  return m_attachedTriangle;
61 }
62 
64 {
65  return m_stencilOnNeighbours[index];
66 }
67 
68 void WVertexProperty::insertStencilNeighbourIDToFront( size_t stencilNeighbourID )
69 {
71  for ( size_t index = m_stencilOnNeighbours.size() - 1; index > 0; index-- )
72  m_stencilOnNeighbours[index] = m_stencilOnNeighbours[index - 1];
73  m_stencilOnNeighbours[0] = stencilNeighbourID;
74 }
75 void WVertexProperty::addStencilNeighbourIDToBack( size_t stencilNeighbourID )
76 {
77  int size = m_stencilOnNeighbours.size();
78  m_stencilOnNeighbours.reserve( size + 1 );
79  m_stencilOnNeighbours.resize( size + 1 );
80  m_stencilOnNeighbours[size] = stencilNeighbourID;
81 }
82 
84 {
85  return m_stencilOnNeighbours.size();
86 }
87 
89 {
90  return m_boundClass;
91 }
92 void WVertexProperty::setBoundClass( int boundClass )
93 {
94  this->m_boundClass = boundClass;
95 }
96 
97 void WVertexProperty::attachTriangle( size_t triangleID )
98 {
99  size_t size = m_attachedTriangle.size();
100  for ( size_t index = 0; index < size; index++ )
101  if ( m_attachedTriangle[index] == triangleID )
102  return;
103 
104  m_attachedTriangle.reserve( size + 1 );
105  m_attachedTriangle.resize( size + 1 );
106  m_attachedTriangle[size] = triangleID;
107 }
108 void WVertexProperty::detachTriangle( size_t triangleID )
109 {
110  size_t size = m_attachedTriangle.size();
111  for ( size_t index = 0; index < size; index++ )
112  {
113  if ( m_attachedTriangle[index] == triangleID )
114  {
115  for ( size_t popIdx = index; popIdx < size-1; popIdx++ )
116  m_attachedTriangle[popIdx] = m_attachedTriangle[popIdx + 1];
117 
118  size--;
119  m_attachedTriangle.resize( size );
120  m_attachedTriangle.reserve( size );
121  }
122  }
123 }
124 
125 bool WVertexProperty::containsTriangle( size_t triangleID )
126 {
127  for ( size_t index = 0; index < getTriangleCount(); index++ )
128  {
129  size_t id = m_attachedTriangle[index];
130  if ( id == triangleID )
131  return true;
132  }
133  return false;
134 }
136 {
137  size_t index = 0;
138  while ( index < this->m_newVertices.size() && this->m_newVertices[index]->getToID() != toID )
139  index++;
140 
141  if ( index >= m_newVertices.size() )
142  {
143  size_t oldSize = m_newVertices.size();
144  m_newVertices.reserve( oldSize + 1 );
145  m_newVertices.resize( oldSize + 1 );
146  size_t newSize = m_newVertices.size();
147  m_newVertices[newSize-1] = new WNewVertex( toID );
148  }
149 }
150 
152 {
153  for ( size_t index = 0; index < this->m_newVertices.size(); index++ )
154  if ( this->m_newVertices[index]->getToID() == toID )
155  return true;
156  return false;
157 }
159 {
160  unsigned int size = this->m_newVertices.size();
161  for ( unsigned int index = 0; index < size; index++ )
162  if ( this->m_newVertices[index]->getToID() == toID )
163  return m_newVertices[index];
164 
165  return 0;
166 }
168 {
169  return this->m_maxNeighbourDistance;
170 }
172 {
173  return this->m_sumNeighbourDistance;
174 }
175 void WVertexProperty::setMaxNeighbourDistance( float maxNeighbourDistance )
176 {
177  this->m_maxNeighbourDistance = maxNeighbourDistance;
178 }
179 void WVertexProperty::setSumNeighbourDistance( float sumNeighbourDistance )
180 {
181  this->m_sumNeighbourDistance = sumNeighbourDistance;
182 }
183 
185 {
186  for ( size_t index = 0; index < getValence(); index++ )
187  if ( getStencilNeighbourID( index ) == neighbourID )
188  return index;
189 
190  return -1;
191 }
192 
194 {
195  return m_newVertices;
196 }
size_t getTriangleCount()
Returns the attached triangle count to the current vertex.
vector< size_t > m_stencilOnNeighbours
List that keeps neighbour vertices IDs sorted by the circular order.
void setSumNeighbourDistance(float sumNeighbourDistance)
Sets the summed neighbor distance within the current vertex.
std::vector< WNewVertex * > getNewVerticesToHigherNeighborID()
Returns the properties of new registered vertices of the current vertex.
bool newVertexExists(size_t toID)
Checks whether the properties of a new vertex exists between the current vertex and toID.
void attachNewVertex(size_t toID)
Attachs properties of a new vertex on a line which lies between two original vertices.
void setMaxNeighbourDistance(float maxNeighbourDistance)
Sets maximal neighbor distance within the current vertex.
float m_maxNeighbourDistance
Maximal Neighbor vertex distance to the current vertex.
vector< size_t > getAttachedTriangles()
Get all triangle IDs attached to the current vertex.
bool containsTriangle(size_t triangleID)
Returns true if a triangle of the triangleID is connected to the vertex.
WNewVertex * getNewVertexProperty(size_t toID)
Returns properties of the new vertex between the current vertex ID and toID.
int getStencilNeighbourIndex(size_t neighbourID)
Returns the Stencil neighbor index of a particular vertex ID.
float getMaxNeighbourDistance()
Returns the maximal neighbor distance within the current vertex.
void setBoundClass(int boundCountClass)
Sets the bound count class of the stencil's center point.
size_t getStencilNeighbourID(size_t index)
Returns a neighbor ID within the stencil by the index.
void addStencilNeighbourIDToBack(size_t stencilNeighbourID)
Pushs a stencil neighbour vertex ID after the last Item of the list.
void attachTriangle(size_t triangleID)
Registers a triangle to the current vertex.
std::vector< WNewVertex * > m_newVertices
List of attached new vertices of the current vertex.
virtual ~WVertexProperty()
Destroys the vertex property object.
float m_sumNeighbourDistance
Sum of all Neighbor vertex distances to the current vertex.
void insertStencilNeighbourIDToFront(size_t stencilNeighbourID)
Pushes a stencil neighbor vertex ID before the first Item of the list.
size_t getValence()
Returns the Neighbor vertex count of the current vertex.
std::vector< size_t > m_attachedTriangle
List of attached triangles to the current vertex.
void detachTriangle(size_t triangleID)
Unregisters a triangle to the current vertex.
WVertexProperty()
Initializes a vertex property object and sets settings to defaults.
float getSumNeighbourDistance()
Returns summed neighbor distance within the current vertex.
int m_boundClass
Depicts the Vertex' kind of bound iit lies on <0: Extraordinary case.
int getBoundClass()
Returns the bound count class of the stencil's center point.
Depicts a point that is subdivided on a line between two vertices.
Definition: WNewVertex.h:40