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

Generated on Wed May 31 15:26:38 2006 for TNTsdk by  doxygen 1.3.8-20040913