![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /******************************************************************************* 00002 ** Copyright (c) 2006 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 *******************************************************************************/ 00005 /******************************************************************************* 00006 ** $RCSfile: netwrkEdge.h,v $ $Revision: 1.26 $ $State: Exp $ 00007 *******************************************************************************/ 00008 #ifndef netwrkEdge_H_ 00009 #define netwrkEdge_H_ 00010 00011 #include "gdb/gdbDefines.h" 00012 #include "gdb/netwrkSeg.h" 00013 #include "gdb/netwrkSpecEl.h" 00014 #include <assert.h> 00015 #include <vlutil/vlConfig.h> 00016 #include <geometry/tdbextent.h> 00017 #include <vector> 00018 #include <list> 00019 #include <memory> 00020 00021 class DtNetworkNode; 00022 class DtNetworkSegmentIterator; 00023 class DtNetworkEdgeTraverser; 00024 00025 // 00026 // DtNetworkEdge represents a section of a network built using a series 00027 // of points that does not intersect any other part of the network. 00028 class DT_DLL_gdb DtNetworkEdge : public DtNetworkSpecElement 00029 { 00030 public: 00031 00032 typedef std::vector<DtPoint> DtPointContainer; 00033 typedef DtPointContainer::iterator DtPointIter; 00034 typedef DtPointContainer::const_iterator DtPointConstIter; 00035 typedef DtPointContainer::reverse_iterator DtPointReverseIter; 00036 typedef DtPointContainer::const_reverse_iterator DtPointConstReverseIter; 00037 00038 typedef std::list<DtNetworkSegment*> DtSegmentContainer; 00039 typedef DtSegmentContainer::iterator DtSegmentIter; 00040 typedef DtSegmentContainer::const_iterator DtSegmentConstIter; 00041 typedef DtSegmentContainer::reverse_iterator DtSegmentReverseIter; 00042 typedef DtSegmentContainer::const_reverse_iterator DtSegmentConstReverseIter; 00043 00044 enum DtTraversalDirection 00045 { 00046 DtForward, 00047 DtBackward 00048 }; 00049 00050 enum DtDirectionality 00051 { 00052 UNI_DIRECTIONAL, 00053 BI_DIRECTIONAL // default 00054 }; 00055 00056 // default constructor 00057 DtNetworkEdge(); 00058 00059 // destructor 00060 // \note Upon destruction, all connected nodes are notified 00061 // that they are no longer connected to the edge. 00062 virtual ~DtNetworkEdge(); 00063 00064 private: 00065 // copy constructor - not implemented 00066 DtNetworkEdge(const DtNetworkEdge& orig); 00067 00068 // assignment operator - not implemented 00069 DtNetworkEdge& operator=(const DtNetworkEdge& orig); 00070 00071 public: 00072 // \return the DtString "DtNetworkEdge" 00073 virtual DtString type(); 00074 00075 // \return the number of points in the edge. 00076 unsigned int numPoints() const; 00077 00078 // \return the directionality of the road. If the road is bidirectional, 00079 // and the user respects this, then only forward iterators over the segments 00080 // may be created. If the edge is bi-directional or if the user ignores 00081 // directionality, then both forward and backward iterators may be created. 00082 // \note The forward direction is defined as the direction from the starting 00083 // point of the edge to the endpoint. 00084 // \note Forward and Backward can also be thought of as Right and Left as they would 00085 // appear to an observer 00086 void setDirectionality(DtDirectionality directionality); 00087 DtDirectionality directionality() const; 00088 00089 00090 // Return auto pointers to edge traversers for this edge. 00091 // \param respectDirectionality If this is true, the traverser will *not* be created for 00092 // one way streets if the desired direction is backwards. 00093 // \note Forward can be described as the direction from the starting 00094 // point of the edge to the end point. 00095 // \note If no parameters are supplied, a Forward traverser is returned (should never fail). 00096 std::auto_ptr<DtNetworkEdgeTraverser> createEdgeTraverser(); 00097 std::auto_ptr<DtNetworkEdgeTraverser> createEdgeTraverser(DtTraversalDirection traversalDirection, 00098 bool respectDirectionality); 00099 00100 std::auto_ptr<const DtNetworkEdgeTraverser> createEdgeTraverser() const; 00101 std::auto_ptr<const DtNetworkEdgeTraverser> createEdgeTraverser(DtTraversalDirection traversalDirection, 00102 bool respectDirectionality) const; 00103 00104 // \return the length of the edge, as a sum of the lengths of the 00105 // segments comprising the edge. 00106 virtual double length() const; 00107 // Computes the closest point on the edge to another point 00108 // \param pointOut the computed closest point 00109 // \param distance the computed distance 00110 virtual void closestPoint(const DtPoint& pointIn, 00111 DtPoint& pointOut, 00112 double& distance) const; 00113 00114 // Computes the distance from the edge to a point. 00115 // \return the closest distance to the specified point. 00116 virtual double distanceToPoint(const DtPoint& point) const; 00117 00118 00119 // Calculates the intersection of the projections onto the x-y plane 00120 // of this edge and the specified segment. 00121 // 00122 // \param seg the segment to test for intersections 00123 // \return a boolean signifying whether or not any intersection occurred. 00124 virtual bool xyIntersects(const DtNetworkSegment& seg) const; 00125 00126 00127 // The same as the above function, but also calculates the specified 00128 // values. 00129 // \param seg the segment to test for intersections. 00130 // \param thisSeg a reference to the segment on this edge, if any, that 00131 // intersects the specified segment. 00132 // \param distanceSquared the distance between the segment and the edge squared. 00133 // \param thisX 00134 // \param thisY These hold the closest points on this edge 00135 // \param otherX 00136 // \param otherY These hold the closest points on the network segment 00137 virtual bool xyIntersects(const DtNetworkSegment& seg, 00138 const DtNetworkSegment*& thisSeg, 00139 double& distanceSquared, 00140 double& thisX, 00141 double& thisY, 00142 double& otherX, 00143 double& otherY) const; 00144 00145 // Calculates the intersection of the projections onto the x-y plane 00146 // of this edge and the specified edge. 00147 // 00148 // \param edge the edge to test for intersections 00149 // \param thisSeg a reference to the segment on this edge that intersects the 00150 // specified edge, if any. 00151 // \param otherSeg a reference to the segment on the specified edge that 00152 // intersects this edge, if any. 00153 // \return a boolean signifying whether or not any intersection occurred. 00154 virtual bool xyIntersects(const DtNetworkEdge& edge, 00155 const DtNetworkSegment*& thisSeg, 00156 const DtNetworkSegment*& otherSeg) const; 00157 00158 // The same as the above function, but also calculates the specified 00159 // values. 00160 // \param edge the edge to test for intersections 00161 // \param thisSeg a reference to the segment on this edge that intersects the 00162 // specified edge, if any. 00163 // \param otherSeg a reference to the segment on the specified edge that 00164 // intersects this edge, if any. 00165 // \param distanceSquared the distance between the edge and the edge squared. 00166 // \param thisX 00167 // \param thisY these hold the closest points on this edge 00168 // \param otherX 00169 // \param otherY these hold the closest points on the edge 00170 virtual bool xyIntersects(const DtNetworkEdge& edge, 00171 const DtNetworkSegment*& thisSeg, 00172 const DtNetworkSegment*& otherSeg, 00173 double& distanceSquared, 00174 double& thisX, 00175 double& thisY, 00176 double& otherX, 00177 double& otherY) const; 00178 00179 // get/set start and end nodes 00180 // \note must be the same location as the 00181 // start and end points of the edge. 00182 // 00183 // \see startPoint() 00184 // \see endPoint() 00185 virtual DtNetworkNode* startNode() const; 00186 // \note If there is an existing start node, it is 00187 // notified of being replaced by another node. 00188 virtual void setStartNode(DtNetworkNode* node); 00189 virtual DtNetworkNode* endNode() const; 00190 // \note If there is an existing end node, it is 00191 // notified of being replaced by another node. 00192 virtual void setEndNode(DtNetworkNode* node); 00193 00194 // If the specified node is either start, end, or both, 00195 // the associated member is set to 0 to remove the 00196 // connection to the node. 00197 // \note Used by nodes to remove themselves from edges 00198 // when they are deleted. Edges may need to respond by 00199 // creating/setting another node if appropriate. 00200 virtual void removeConnection(DtNetworkNode* node); 00201 00202 // \return the first and last endpoints respectively 00203 virtual DtPoint endpoint0() const; 00204 virtual DtPoint endpoint1() const; 00205 00206 virtual bool pointInEdge(const DtPoint& point) const; 00207 virtual bool addPoint(const DtPoint& newPoint); 00208 virtual bool addPointToStart(const DtPoint& newPoint); 00209 00210 // Returns the point at the particular index 00211 const DtPoint& point(int i) const; 00212 DtPoint& point(int i); 00213 00214 // \return the extent of the edge 00215 virtual DtExtent extent() const; 00216 00217 // \return an actual iterator, const or non-const, to the beginning or 00218 // the end of the list of segments 00219 // \note These give *direct* access to the edges segments, regardless of 00220 // directionality! 00221 DtPointIter pointsBegin(); 00222 DtPointConstIter pointsBegin() const; 00223 00224 DtPointIter pointsEnd(); 00225 DtPointConstIter pointsEnd() const; 00226 00227 // \return a reverse iterator, const or non-const, to the beginning or 00228 // the end of the segments 00229 // \note These give *direct* access to the edges segments, regardless of 00230 // directionality! 00231 DtPointReverseIter rPointsBegin(); 00232 DtPointConstReverseIter rPointsBegin() const; 00233 00234 DtPointReverseIter rPointsEnd(); 00235 DtPointConstReverseIter rPointsEnd() const; 00236 00237 00238 // Returns a new segment in the edge. 00239 // \note If this edge is associated with a vector network, 00240 // the segment is owned by the vector network. Otherwise, 00241 // it is owned by the edge. 00242 DtNetworkSegment* newSegment(); 00243 00244 // \return an actual iterator, const or non-const, to the beginning or 00245 // the end of the list of segments 00246 // \note These give *direct* access to the edges segments, regardless of 00247 // directionality! 00248 DtSegmentIter segmentsBegin(); 00249 DtSegmentConstIter segmentsBegin() const; 00250 00251 DtSegmentIter segmentsEnd(); 00252 DtSegmentConstIter segmentsEnd() const; 00253 00254 // \return a reverse iterator, const or non-const, to the beginning or 00255 // the end of the segments 00256 // \note These give *direct* access to the edges segments, regardless of 00257 // directionality! 00258 DtSegmentReverseIter rSegmentsBegin(); 00259 DtSegmentConstReverseIter rSegmentsBegin() const; 00260 00261 DtSegmentReverseIter rSegmentsEnd(); 00262 DtSegmentConstReverseIter rSegmentsEnd() const; 00263 00264 virtual void setVectorNetwork(DtVectorNetwork* vectorNetwork); 00265 virtual DtVectorNetwork* vectorNetwork() const; 00266 00267 // Returns references to the lists of points and segments contained 00268 // in the edge 00269 // \note Users should almost never need to use these functions, and should 00270 // be very careful when doing so as these functions may lead to corruption 00271 // of the edge instance. 00272 DtPointContainer& points(); 00273 const DtPointContainer& points() const; 00274 DtSegmentContainer& segments(); 00275 const DtSegmentContainer& segments() const; 00276 00277 virtual int sizeInBytes() const; 00278 00279 protected: 00280 bool testInvariant() const; 00281 00282 DtVectorNetwork* myVectorNetwork; 00283 DtDirectionality myDirectionality; 00284 DtPointContainer myPoints; 00285 // edge owns these segments and is responsible for deleting them. 00286 DtSegmentContainer mySegments; 00287 00288 // Does not own the nodes, and should never delete them 00289 DtNetworkNode* myStartNode; 00290 DtNetworkNode* myEndNode; 00291 00292 double myLength; 00293 }; 00294 00295 // For backwards compatibility - remove later. 00296 typedef DtNetworkEdge::DtSegmentIter DtNetworkSegmentIter; 00297 typedef DtNetworkEdge::DtSegmentConstIter DtNetworkSegmentConstIter; 00298 typedef DtNetworkEdge::DtSegmentReverseIter DtNetworkSegmentReverseIter; 00299 typedef DtNetworkEdge::DtSegmentConstReverseIter DtNetworkSegmentConstReverseIter; 00300 00301 inline const DtPoint& DtNetworkEdge::point(int i) const 00302 { 00303 return myPoints[i]; 00304 } 00305 00306 inline DtPoint& DtNetworkEdge::point(int i) 00307 { 00308 return myPoints[i]; 00309 } 00310 00311 #endif