00001
00018 #ifndef INC_MI32_TINRC16_H
00019 #define INC_MI32_TINRC16_H
00020
00021 #ifndef INC_MI32_DELEGATE_H
00022 #include <mi32/delegate.h>
00023 #endif
00024
00025 #ifndef INC_MI32_SIMPLEAR_H
00026 #include <mi32/simplear.h>
00027 #endif
00028
00029 #ifndef INC_MI32_DOUBLEAR_H
00030 #include <mi32/doublear.h>
00031 #endif
00032
00033 #ifndef INC_MI32_POINT_H
00034 #include <mi32/point.h>
00035 #endif
00036
00037
00038
00040 class TIN_RC16 {
00041 private:
00042 #ifndef GENERATING_DOXYGEN_OUTPUT
00043
00044 struct EDGE {
00045 INT32 m_NodeStart;
00046 INT32 m_NodeEnd;
00047 INT32 m_TriangleLeft;
00048 INT32 m_TriangleRight;
00049 UINT32 m_Length2;
00050 };
00051
00052 struct TRIANGLE {
00053 INT32 m_Node[3];
00054 INT32 m_Edge[3];
00055
00056 int GetNodePosOpposite (INT32 EdgeIdx) const
00057 { return ((m_Edge[1] == EdgeIdx) ? 0 : (m_Edge[2] == EdgeIdx) ? 1 : 2); }
00058 };
00059
00060 #endif
00061
00062 public:
00063
00065 struct NODE {
00066 INT16 m_row;
00067 INT16 m_col;
00068 };
00069
00070 struct PLANE {
00071 double m_Zrow;
00072 double m_Zcol;
00073 double m_Z0;
00074 };
00075
00077 struct TRINODE {
00078 NODE m_Node[3];
00079
00081 void CalcNormal (
00082 const double *values,
00083 DPOINT3D& normal
00084 ) const;
00085
00087 void CalcPlane (
00088 const double *values,
00089 PLANE& plane
00090 ) const;
00091 };
00092
00094 class FILLER {
00095 public:
00097 FILLER (const TIN_RC16& tin);
00098
00100 virtual ~FILLER ();
00101
00105 void Process ();
00106
00107 private:
00108 #ifndef GENERATING_DOXYGEN_OUTPUT
00109 const TIN_RC16& m_tin;
00110
00111 void FillTriangle (const TRIANGLE& triangle);
00112 #endif
00113
00114
00115
00116 virtual void v_FillBegin (
00117 const TRINODE& trinode
00118 );
00119
00120 virtual void v_FillSpan (
00121 INT16 row,
00122 INT16 col,
00123 UINT16 num
00124 ) = 0;
00125 };
00126
00128 class FILLER_MEM_DOUBLE : public FILLER {
00129 public:
00130
00132 FILLER_MEM_DOUBLE (
00133 const TIN_RC16& tin,
00134 double *data,
00135 UINT16 NumRows,
00136 UINT16 NumCols
00137 );
00138
00140 ~FILLER_MEM_DOUBLE ();
00141
00142 private:
00143 #ifndef GENERATING_DOXYGEN_OUTPUT
00144 double *m_data;
00145 INT32 m_NumRows;
00146 INT32 m_NumCols;
00147 PLANE m_Plane;
00148
00149 INT32 CalcIdx (INT16 row, INT16 col) const
00150 { return (row * m_NumCols + col); }
00151
00152 virtual void v_FillBegin (const TRINODE& trinode);
00153 virtual void v_FillSpan (INT16 row, INT16 col, UINT16 num);
00154 #endif
00155 };
00156
00158 typedef fastdelegate::FastDelegate<double(INT16,INT16)> DELEGATE_GETVALUE;
00159
00161 TIN_RC16 ();
00162
00164 ~TIN_RC16 ();
00165
00167 ERRVALUE AddRowCells (
00168 INT16 row,
00169 const INT16 *columns,
00170 UINT32 NumColumns
00171 );
00172
00174 ERRVALUE CalcNodeNormals (
00175 DELEGATE_GETVALUE DelegateGetValue,
00176 double rowscale,
00177 double colscale,
00178 DOUBLE_ARRAY<DPOINT3D>& NodeNormals
00179 ) const;
00180
00183 ERRVALUE Finalize ();
00184
00186 const SIMPLE_ARRAY<NODE>& GetNodes () const
00187 { return (m_Nodes); }
00188
00191 ERRVALUE Initialize ();
00192
00193 private:
00194 #ifndef GENERATING_DOXYGEN_OUTPUT
00195
00196 INT32 m_RowPrev;
00197 SIMPLE_ARRAY<NODE> m_Nodes;
00198 SIMPLE_ARRAY<EDGE> m_Edges;
00199 SIMPLE_ARRAY<INT32> m_EdgeIdxTop;
00200 SIMPLE_ARRAY<INT32> m_EdgeIdxBottom;
00201 SIMPLE_ARRAY<INT32> m_EdgeIdxWork;
00202 SIMPLE_ARRAY<INT32> m_EdgeIdxTest;
00203 SIMPLE_ARRAY<INT32> m_TriangleIdxTest;
00204 SIMPLE_ARRAY<TRIANGLE> m_Triangles;
00205
00206 ERRVALUE DoRowNodes (INT16 row, INT32& NodeIdx);
00207
00208 INT32 EdgeAdd (INT32 NodeIdx1, INT32 NodeIdx2);
00209
00210 void EdgeTestAdd (INT32 EdgeIdx, INT32 TriangleIdx);
00211
00212 int EdgeTestCell (const EDGE& Edge, INT16 row, INT16 col) const
00213 { return (NodesTestCell(Edge.m_NodeStart,Edge.m_NodeEnd,row,col)); }
00214
00215 int EdgeTestCell (INT32 EdgeIdx, INT16 row, INT16 col) const
00216 { return (EdgeTestCell(m_Edges[EdgeIdx],row,col)); }
00217
00218 void EdgeTestResplit (INT32 EdgeIdx, INT32 TriangleIdx);
00219
00220 void EdgeTestSliver (INT32 EdgeIdx, SIMPLE_ARRAY<INT32>& EdgeIdxTest);
00221
00222 INT32 NodeAdd (INT16 row, INT16 col);
00223
00224 UINT32 NodeCalcDistance2 (INT32 NodeIdx1, INT32 NodeIdx2) const
00225 {
00226 INT32 drow = m_Nodes[NodeIdx2].m_row - m_Nodes[NodeIdx1].m_row;
00227 INT32 dcol = m_Nodes[NodeIdx2].m_col - m_Nodes[NodeIdx1].m_col;
00228 return (drow*drow + dcol*dcol);
00229 }
00230
00231 int NodesTestCell (INT32 NodeIdxStart, INT32 NodeIdxEnd, INT16 row, INT16 col) const
00232 { return (NodesTestCell(m_Nodes[NodeIdxStart],m_Nodes[NodeIdxEnd],row,col)); }
00233
00234 int NodesTestCell (const NODE& NodeStart, const NODE& NodeEnd, INT16 row, INT16 col) const
00235 {
00236 INT32 drows = NodeEnd.m_row - NodeStart.m_row;
00237 INT32 dcols = NodeEnd.m_col - NodeStart.m_col;
00238 INT32 trows = row - NodeStart.m_row;
00239 INT32 tcols = col - NodeStart.m_col;
00240 return (dcols * trows - drows * tcols);
00241 }
00242
00243 ERRVALUE TriangleAdd (INT32 NodeIdx0, INT32 NodeIdx1, INT32 NodeIdx2, INT32 EdgeIdx01, INT32 EdgeIdx12, INT32 EdgeIdx20);
00244 bool TriangleTestNodeInCircle (const TRIANGLE& Triangle, const NODE& Node) const;
00245
00246 #if defined(WIN32) && defined(DEBUG)
00247 void TriangleAssertValid (INT32 TriangleIdx) const;
00248 #endif
00249
00250 TIN_RC16 (const TIN_RC16&);
00251 TIN_RC16& operator= (const TIN_RC16&);
00252
00253 #endif
00254 };
00255
00256
00257
00258 #endif // INC_MI32_TINRC16_H