00001
00002
00003 #ifndef Terrain_H
00004 #define Terrain_H
00005
00006 #define MAXFEATURES 10
00007
00008
00009 #include "Assembly.h"
00010 #include "DH_Chain.h"
00011 #include "Scene.h"
00012 #include "Point.h"
00013
00021 class TerrainControl : public controlable {
00022 public:
00023 TerrainControl() {}
00024
00025 ~TerrainControl() {}
00026
00027 virtual void register_at(ControlDevice& Ctrl) {}
00028
00029 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00030 char VariableName[32];
00031
00032 std::sprintf(VariableName,"Terrain");
00033 #ifdef TERRAIN_DEBUG_ON
00034 std::cout << "Registering " << VariableName << std::endl;
00035 #endif
00036 TLocCtrl = Ctrl.getSubDevice(std::string(VariableName));
00037 RegisterAt(TLocCtrl,"Terrain_name",terrain_name);
00038 RegisterAt(TLocCtrl,"Terrain_file",terrain_file);
00039 RegisterAt(TLocCtrl,"Terrain_filetype",terrain_filetype);
00040
00041 RegisterAt(TLocCtrl,"n(0)",normal(0));
00042 RegisterAt(TLocCtrl,"n(1)",normal(1));
00043 RegisterAt(TLocCtrl,"n(2)",normal(2));
00044 }
00045
00046 void print() {
00047 std::cout << " -=-=-=-= Terrain CONTROL DEVICE\n\n"
00048 << " terrain_name = " << terrain_name << std::endl;
00049 }
00050
00051 public:
00052
00053 PType normal;
00054
00055 std::string terrain_name, terrain_file;
00056
00057 int terrain_filetype;
00058
00059 ControlDevice TLocCtrl;
00060 };
00061
00062 class Terrain {
00063 typedef Assembly<DataType,3> AssemblyType;
00064 typedef Scene<DataType,3> SceneType;
00065 typedef Loft<DataType> LoftType;
00066 typedef Joint<DataType,3> JointType;
00067 typedef DH_Link<DataType,3> LinkType;
00068 typedef DH_Chain<DataType,3> ChainType;
00069 public:
00070 friend class Turbine;
00071
00072 Terrain() {}
00073
00074 ~Terrain() {}
00075
00076 bool build(int i, std::string name, std::string file, int type) {
00077 Terrain0->GetNthPart(i)->read(type,file);
00078 Terrain0->GetNthPart(i)->setName(name);
00079 return true;
00080 }
00081
00082 virtual bool specificSetup(SceneType& ThisScene, TerrainControl * TerrainCtrl) {
00083 #ifdef TERRAIN_DEBUG_ON
00084 ( mklog() << "\n\n*********\t Terrain specificSetup \tBegin\n*********" << std::endl ).flush();
00085 #endif
00086 Terrain0 = new AssemblyType;
00087 std::string nameTmp;
00088 nameTmp = "hills";
00089 Terrain0->setName(TerrainCtrl->terrain_name);
00090
00091 ThisScene.AddAssembly(*Terrain0);
00092
00093 Terrain0 = ThisScene.GetNthAssembly(ThisScene.GetNumAssemblies()-1);
00094
00095 LoftType * Ground;
00096 Ground = new LoftType;
00097 Terrain0->AddPart(Ground);
00098 Terrain0->GetNthPart(0)->read(TerrainCtrl->terrain_filetype,TerrainCtrl->terrain_file);
00099 nameTmp = "ground_loft";
00100 Terrain0->GetNthPart(0)->setName(TerrainCtrl->terrain_name);
00101 Ground = (LoftType *) Terrain0->GetNthPart(0);
00102 #ifdef TERRAIN_DEBUG_ON
00103 ( mklog() << "Terrain:= " << Ground->Name() << " stringID = " << stringID( Ground->IdTag() ) << std::endl ).flush();
00104 #endif
00105
00106 MType groundMat(4,4);
00107 PType groundNormal(0.);
00108 groundNormal(0) = 180; groundNormal(1) = -90; groundNormal(2) = 0;
00109 groundMat = rotMat3D(TerrainCtrl->normal);
00110 Ground->setDHMat(groundMat);
00111 Ground->setDHMat_old(groundMat);
00112 Ground->setMobility(0);
00113 Ground->setDeformation(0);
00114
00115 Terrain0->updateAssembly(1,0,groundMat,0);
00116 #ifdef TERRAIN_DEBUG_ON
00117 ( mklog() << "\t Ground Mat \n\t" << Ground->GetDHMat()
00118 << " Ground->GetNumVelocities() = " << Ground->GetNumVelocities() << std::endl ).flush();
00119 #endif
00120 return true;
00121 }
00122
00123 virtual PType surfacePoint(PType I_A, DataType zmin, int& flag) {
00124 PType I_B(I_A);
00125 I_B(2) = zmin;
00126 int nump = 0, numc = 0;
00127 Terrain0->GetNumPC(nump,numc);
00128 #ifdef TERRAIN_DEBUG_ON
00129 ( mklog() << " I_A " << I_A << " I_B " << I_B << std::endl
00130 << "SurfacePoint nump = " << nump << " numc = " << numc << std::endl ).flush();
00131 #endif
00132
00133 Terrain0->makeVerticies(nump);
00134 Terrain0->makeConnections(numc);
00135
00136 DataType scale = 1.;
00137 nump = 0;
00138 numc = 0;
00139 Terrain0->send2CPT(nump, numc, Terrain0->GetVerticies(), Terrain0->GetConnections(), scale);
00140 I_B = intersection_line2facet(I_A, I_B, nump, numc, Terrain0->GetVerticies(), Terrain0->GetConnections(),flag );
00141 return I_B;
00142 }
00143
00144 virtual PType surfacePoint(PType I_A, DataType zmin, int flag, DataType off ) {
00145 PType I_B(I_A);
00146 I_B(2) = zmin;
00147 int nump = 0, numc = 0;
00148 Terrain0->GetNumPC(nump,numc);
00149 #ifdef TERRAIN_DEBUG_ON
00150 ( mklog() << "TERRAIN I_A " << I_A << " I_B " << I_B << std::endl
00151 << "SurfacePoint nump = " << nump << " numc = " << numc << std::endl ).flush();
00152 #endif
00153
00154 Terrain0->makeVerticies(nump);
00155 Terrain0->makeConnections(numc);
00156
00157 DataType scale = 1.;
00158 nump = 0;
00159 numc = 0;
00160 Terrain0->send2CPT(nump, numc, Terrain0->GetVerticies(), Terrain0->GetConnections(), scale);
00161 I_B = intersection_line2facet(I_A, I_B, nump, numc, Terrain0->GetVerticies(), Terrain0->GetConnections(),flag );
00162 I_A =(I_A-I_B);
00163 I_B = I_B + off*normalize(I_A);
00164
00165 return I_B;
00166 }
00167
00168 DataType height(PType& I_A, DataType zmin, int& flag) {
00169 DataType h=0.;
00170 PType surfPt;
00171
00172 surfPt = surfacePoint(I_A, zmin, flag);
00173 h = norm_2(surfPt-I_A);
00174 I_A = surfPt;
00175 return h;
00176 }
00177
00178 virtual void Restart(std::ifstream& ifs, int& pos, double& t, double& dt) {
00179 ( mklog() << "\nRestarting Terrain " << Terrain0->Name() << " time= "<< t << " dt = " << dt << std::endl ).flush();
00180 Terrain0->Restart(ifs,pos,t,dt);
00181 pos = ifs.tellg();
00182 }
00183
00184 virtual void Checkpointing(std::ofstream& ofs) {
00185 #ifdef CHECKRESTART_DEBUG_ON
00186 ( mklog() << "\nCHECKPOINTING Terrain " << std::endl ).flush();
00187 #endif
00188 Terrain0->Checkpointing(ofs);
00189 }
00190
00191 protected:
00192
00193 AssemblyType * Terrain0;
00194
00195 };
00196
00197 #endif
00198
00199