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

Generated on Thu Apr 26 04:03:29 2007 for TNTsdk by  doxygen 1.5.2