3dterra.h

Go to the documentation of this file.
00001 /*** 
00002  * \file 3dterra.h <gre/3dterra.h>
00003  * \brief Base class for terrain algorithm
00004  *
00005  * \if NODOC
00006  * $Id: 3dterra.h_v 1.25 2004/10/29 17:35:43 vdronov Exp $
00007  *
00008  * $Log: 3dterra.h_v $
00009  * Revision 1.25  2004/10/29 17:35:43  vdronov
00010  * changed controller
00011  *
00012  * Revision 1.24  2004/09/03 16:56:24  vdronov
00013  * *** empty log message ***
00014  *
00015  * Revision 1.23  2004/08/11 23:03:36  vdronov
00016  * *** empty log message ***
00017  *
00018  * Revision 1.22  2004/08/03 20:30:35  vdronov
00019  * *** empty log message ***
00020  *
00021  * Revision 1.21  2004/07/30 19:09:38  vdronov
00022  * *** empty log message ***
00023  *
00024  * Revision 1.20  2004/06/28 20:42:33  vdronov
00025  * *** empty log message ***
00026  *
00027  * Revision 1.19  2004/06/15 15:42:52  vdronov
00028  * added flat triangulation
00029  *
00030  * Revision 1.18  2004/03/05 17:01:43  mju
00031  * Use virtual dtor if class has virtual fns.
00032  *
00033  * Revision 1.17  2003/12/22 17:37:25  vdronov
00034  * Added PiecewiseTIN model
00035  *
00036  * Revision 1.16  2003/09/15 13:48:59  fileserver!dwilliss
00037  * Doxygen
00038  *
00039  * Revision 1.15  2003/08/26 15:34:35  vdronov
00040  * added VariableTriangulation
00041  *
00042  * Revision 1.14  2003/08/15 17:44:48  vdronov
00043  * nc.
00044  *
00045  * Revision 1.11  2003/07/30 14:20:45  mju
00046  * Check inclusion guards.
00047  * Ignore private section.
00048  * Standardize design.
00049  *
00050  * Revision 1.10  2003/05/28 19:31:18  vdronov
00051  * added dense ray casting
00052  *
00053  * Revision 1.7  2003/04/14 17:31:04  vdronov
00054  * added GetModel
00055  *
00056  * Revision 1.6  2003/04/09 19:12:43  vdronov
00057  * terrain null value
00058  *
00059  * Revision 1.5  2003/04/08 17:50:57  vdronov
00060  * changed triangulation structure
00061  *
00062  * Revision 1.1  2003/03/10 15:07:45  vdronov
00063  * Initial revision
00064  * \endif
00065 **/ 
00066 
00067 #ifndef  INC_GRE_3DTERRA_H
00068 #define  INC_GRE_3DTERRA_H
00069 
00070 #ifndef  INC_GRE_3DDC_H
00071 #include <gre/3ddc.h>
00072 #endif
00073 
00074 #ifndef  INC_MI32_ASURFACE_H
00075 #include <mi32/asurface.h>
00076 #endif
00077 
00078 #ifndef  INC_MI32_SIMPLEAR_H
00079 #include <mi32/simplear.h>
00080 #endif
00081 
00082 #ifndef  INC_RVC_GEOREFER_H
00083 #include <rvc/georefer.h>
00084 #endif
00085 
00086 namespace GRE {
00087 
00088 #ifndef GENERATING_DOXYGEN_OUTPUT
00089 class TEXTUREFILTER;
00090 class TEXTURE;
00091 class CONTROLLER;
00092 
00093 #endif // GENERATING_DOXYGEN_OUTPUT
00094 
00095 //! Base class for 3D terrain models.
00096 class TERRAIN {
00097    public:
00098 
00099       enum MODEL {
00100          MODEL_Default = 0,
00101          MODEL_TIN = 0,
00102          MODEL_SparseTriangulation = 1,
00103          MODEL_DenseTriangulation = 2,
00104          MODEL_RayCasting = 3,
00105          MODEL_DenseRayCasting = 4,
00106          MODEL_VariableTriangulation = 5,
00107          MODEL_PiecewiseTIN = 6,
00108          MODEL_FlatTriangulation = 7,
00109          MODEL_Count = 8
00110          };
00111 
00112 
00113       //! static GetName returns a name of the given model enum
00114       //!
00115       //! @return char pointer of the name
00116       static const char* GetName (
00117          const MODEL model
00118          );
00119 
00120       //! static GetDescription returns a description of the given model enum
00121       //!
00122       //! @return char pointer of the description
00123       static const char* GetDescription (
00124          const MODEL model
00125          );
00126 
00127       //! static GetInstance returns a new instance of the given model enum
00128       //!
00129       //! @return pointer to new model
00130       static TERRAIN* GetInstance (
00131          const MODEL model
00132          );
00133 
00134       virtual ~TERRAIN (                                 //! Constructor 
00135          );
00136 
00137       //! GetName returns a name of the model
00138       //!
00139       //! @return char pointer of the name
00140       const char* GetName (
00141          ) const { return m_Name; }
00142 
00143       //! GetDescription returns a description of the model
00144       //!
00145       //! @return char pointer of the description
00146       const char* GetDescription (
00147          ) const {return m_Description; }
00148 
00149       //! GetModel returns an enum of the model
00150       //!
00151       //! @return enum of the model
00152       const MODEL GetModel (
00153          ) const {return m_Model; }
00154 
00155       //! Create new instance of terrain model
00156       //!
00157       //! @return instance of texture model
00158       TERRAIN* CreateInstance () { return v_CreateInstance(); }
00159 
00160       //!   Build internal structures for terrain construction for given surface layer 
00161       //!
00162       //! @return 0 if built or < 0 if an error
00163       ERRVALUE Build (
00164          const GRE_LAYER *layer
00165          ) { return v_Build(layer); }
00166 
00167       //!   Is internal structures for terrain construction built? 
00168       //!
00169       //! @return true if built or false if an error
00170       bool IsBuilt (
00171          ) const { return m_Built; }
00172 
00173       //!   What rvc object type are supported in surface layer for this model (RVC::TIN or RVC::RASTER)
00174       //!
00175       //! @return true if built or false if an error
00176       bool IsObjectTypeSupported (
00177          const RVC::OBJTYPE objtype
00178          ) const { return v_IsObjectTypeSupported(objtype); }
00179 
00180       //!   Free internal structures for terrain construction 
00181       void Free () {v_Free(); }
00182 
00183       //!   GetDefaultScene initializes scene with default parameters for this model.
00184       //!
00185       //! @return >= 0 if initialization is done
00186       ERRVALUE GetDefaultScene ( 
00187          SCENE3D& scene
00188          ) { return v_GetDefaultScene(scene); }
00189 
00190       //!   Set scene for the model and array of textures to be drawn on it
00191       //!
00192       //! @return >= 0 if set is done
00193       ERRVALUE SetScene (
00194          const SCENE3D& scene,
00195          const SIMPLE_ARRAY<TEXTURE*> &textures
00196          ) { return v_SetScene(scene,textures); }
00197 
00198       //!   Draw given texture with given texture filter on this terrain with preset scene
00199       //!
00200       //! @return >= 0 if set is done
00201       ERRVALUE DrawScene (
00202          CONTROLLER &controller,        
00203          DRAWINGCONTEXT3D& drawing,
00204          TEXTURE* texture,
00205          TEXTUREFILTER* texturefilter
00206          ) { return v_DrawScene(controller, drawing, texture, texturefilter); }
00207 
00208       //! Get extents in map projection coordinates
00209       //!
00210       //! @return extents
00211       const DRECT3D& GetExtents (
00212          ) {return v_GetExtents(); }
00213 
00214       //! Get profile on elevation along polyline
00215       //!
00216       //! @return 0 or an error
00217       ERRVALUE ComputeProfile (
00218          const POLYLINE& polyline,
00219          POLYLINE& profile,
00220          SIMPLE_ARRAY<INT32>& index
00221          ) {return v_ComputeProfile(polyline, profile, index); }
00222 
00223 
00224       //! Get elevation at map projection coordinates (x, y)
00225       //!
00226       //! @return elevation in meters
00227       float GetElevation (
00228          const float x,
00229          const float y
00230          ) {return v_GetElevation(x,y); }
00231 
00232       //! Get angle to elevation at map projection coordinates (x, y)
00233       //!
00234       //! @return angle to north in radians
00235       float GetAngleToNorth (
00236          const float x,
00237          const float y
00238          ) const { return v_GetAngleToNorth(x, y); }
00239 
00240       //! Get abstract surface pointer
00241       //!
00242       //! @return pointer ot abstruct surface maybe 0
00243       const ABSTRACT_SURFACE* GetAbstractSurface (
00244          ) { return v_GetAbstractSurface(); }
00245 
00246       //! Has null areas
00247       //!
00248       //! @return true if has null areas
00249       bool HasNull (
00250          ) const { return v_HasNull(); }
00251 
00252 
00253       //! Is value at map projection coordinates (x, y) null
00254       //!
00255       //! @return true if value is null
00256       bool IsNull (
00257          const float x,
00258          const float y
00259          ) const { return v_IsNull(x,y); }
00260 
00261       //! Set model map projection be used for output data
00262       void SetCoordRefSys (
00263          const SPATREF::COORDREFSYS& CoordRefSys
00264          ) { v_SetCoordRefSys(CoordRefSys); }
00265 
00266       //! Get map projection be used for output data 
00267       //!
00268       //! @return MAPPROJPARM
00269       const SPATREF::COORDREFSYS GetCoordRefSys (
00270          ) const { return v_GetCoordRefSys(); }
00271 
00272       void ClearBoundary (
00273          ) { 
00274          m_Boundary.Clear();
00275          return;
00276          };
00277 
00278       const REGION2D& GetBoundary (
00279          ) { 
00280          if (m_Boundary.IsEmpty()) v_CreateBoundary(m_Boundary); 
00281          return m_Boundary;
00282          };
00283 
00284       bool IsBoundaryChanged (
00285          ) const { 
00286          return m_Boundary.IsEmpty();
00287          };
00288 
00289       bool IsTerrainDynamic (
00290          ) const { 
00291          return false;
00292          };
00293 
00294    protected:
00295 
00296       //! Register this model (Called by constructor)
00297       static void Register (
00298          TERRAIN* terrain
00299          );
00300 
00301       TERRAIN (                                 //! Constructor 
00302          const char* name,
00303          const char* desc,
00304          const MODEL model
00305          );
00306 
00307       //!   Set built state.
00308       void SetBuilt (
00309          const bool built
00310          ) {m_Built = built; }
00311 
00312    private:
00313 
00314       #ifndef GENERATING_DOXYGEN_OUTPUT
00315 
00316       static TERRAIN* s_TerrainModels[MODEL_Count];
00317 
00318       const char* m_Name;
00319       const char* m_Description;
00320       const MODEL m_Model;
00321       bool m_Built;                                //!<  Is an object built?
00322 
00323       REGION2D m_Boundary;
00324 
00325       TERRAIN (                                 //! Constructor 
00326          );
00327 
00328       TERRAIN (                                 //! Copy constructor (not implemented)
00329          const TERRAIN &rhs
00330          );
00331 
00332       TERRAIN& operator= (                      //! Assignment operator (not implemented)
00333          const TERRAIN& rhs
00334          );
00335 
00336       #endif //!< GENERATING_DOXYGEN_OUTPUT
00337 
00338       virtual TERRAIN* v_CreateInstance (
00339          ) = 0;
00340 
00341       virtual ERRVALUE v_Build (
00342          const GRE_LAYER *layer
00343          ) = 0;
00344 
00345       virtual bool v_IsObjectTypeSupported (
00346          const RVC::OBJTYPE objtype
00347          ) const = 0;
00348 
00349       virtual void v_Free (
00350          ) = 0;
00351 
00352       virtual ERRVALUE v_GetDefaultScene ( 
00353          SCENE3D& scene
00354          ) const = 0;
00355 
00356       virtual ERRVALUE v_SetScene (
00357          const SCENE3D& scene,
00358          const SIMPLE_ARRAY<TEXTURE*> &textures
00359          ) = 0;
00360 
00361       virtual ERRVALUE v_DrawScene (
00362          CONTROLLER &controller,        
00363          DRAWINGCONTEXT3D& drawing,
00364          TEXTURE* texture,
00365          TEXTUREFILTER* texturefilter
00366          ) = 0;
00367 
00368       virtual const DRECT3D& v_GetExtents (
00369          ) = 0;
00370 
00371       virtual void v_CreateBoundary (
00372          REGION2D& boundary
00373          ) = 0;
00374 
00375       virtual float v_GetElevation (
00376          const float x,
00377          const float y
00378          ) const = 0;
00379 
00380       virtual ERRVALUE v_ComputeProfile (
00381          const POLYLINE& polyline,
00382          POLYLINE& profile,
00383          SIMPLE_ARRAY<INT32>& index
00384          ) = 0;
00385 
00386       virtual float v_GetAngleToNorth (
00387          const float x,
00388          const float y
00389          ) const = 0;
00390 
00391       virtual const ABSTRACT_SURFACE* v_GetAbstractSurface (
00392          ) = 0;
00393 
00394       virtual bool v_HasNull (
00395          ) const  = 0;
00396 
00397       virtual bool v_IsNull (
00398          const float x,
00399          const float y
00400          ) const  = 0;
00401 
00402       virtual void v_SetCoordRefSys (
00403          const SPATREF::COORDREFSYS& CoordRefSys
00404          ) = 0;
00405 
00406       virtual const SPATREF::COORDREFSYS v_GetCoordRefSys (
00407          ) const = 0;
00408    };
00409 
00410 
00411 //! Base class for 3D terrain controller.
00412 //! This class is designed for buffering of terrain constructions 
00413 class CONTROLLER {
00414    public:
00415 
00416       //! Called by terrain model on begining of terrain constuctions
00417       void OnBegin () { v_OnBegin(); }
00418 
00419       //! Called by terrain model on ending of terrain constuctions
00420       void OnEnd () { v_OnEnd(); }
00421 
00422       //! Called by terrain model on full(partial) triangulation
00423       void OnTriangulation (  
00424          DRAWINGCONTEXT3D& drawing,
00425          const TRIANGULATION& triangulation
00426          ) { v_OnTriangulation(drawing, triangulation); }
00427 
00428       //! Called by terrain model on full(partial) pixalization
00429       void OnPixalization (   
00430          DRAWINGCONTEXT3D& drawing,
00431          const PIXALIZATION& pixalization
00432          ) { v_OnPixalization(drawing, pixalization); }
00433 
00434    protected:
00435 
00436       CONTROLLER () {}
00437 
00438       virtual ~CONTROLLER () {}
00439 
00440    private:
00441 
00442       virtual void v_OnBegin (
00443          ) = 0;
00444 
00445       virtual void v_OnEnd (  
00446          ) { }
00447 
00448       virtual void v_OnTriangulation (    
00449          DRAWINGCONTEXT3D& drawing,
00450          const TRIANGULATION& triangulation
00451          ) = 0;
00452 
00453       virtual void v_OnPixalization (  
00454          DRAWINGCONTEXT3D& drawing,
00455          const PIXALIZATION& pixalization
00456          ) = 0;
00457 
00458    };
00459 
00460 
00461 //! Simple implementation of 3D terrain controller.
00462 class SIMPLECONTROLLER : public GRE::CONTROLLER {
00463    public:
00464       virtual ~SIMPLECONTROLLER () {}
00465 
00466    private:
00467       #ifndef GENERATING_DOXYGEN_OUTPUT
00468 
00469       GRE::TRIANGULATIONVECTOR m_Triangulations;
00470       GRE::PIXALIZATIONVECTOR m_Pixalizations;
00471 
00472       void v_OnBegin (
00473          );
00474 
00475       void v_OnEnd (    
00476          );
00477 
00478       void v_OnTriangulation (   
00479          DRAWINGCONTEXT3D& drawing,
00480          const GRE::TRIANGULATION& triangulation
00481          );
00482 
00483       void v_OnPixalization (    
00484          DRAWINGCONTEXT3D& drawing,
00485          const GRE::PIXALIZATION& pixalization
00486          );
00487 
00488       #endif //!< GENERATING_DOXYGEN_OUTPUT
00489    };
00490 
00491 }     //! End of namespace
00492 
00493 #endif
00494 

Generated on Tue Dec 14 13:18:11 2004 for TNTsdk by  doxygen 1.3.8-20040913