00001 #include <j2k/Fred/3d/Modeleur.hpp>
00002 #include <j2k/Fred/3d/Model.hpp>
00003 #include "boite.h"
00004
00005 #include <string.h>
00006 #include <math.h>
00007
00008 #define __modeopen_fic_error "Modeleur : Bad File open."
00009 #define __modewrite_fic_error "Modeleur : Bad File write."
00010
00011 char* G_defaultname = "__modelx";
00012
00013 char* G_modetbmsg[] = {
00014 __modeopen_fic_error,
00015 __modewrite_fic_error
00016 };
00017
00018 AxisCAO::AxisCAO (
00019 char* name,
00020 Cardinal c,
00021 Sommet3D* pf,
00022 Vector3D& v,
00023 UINT p
00024
00025 ) : cardprofil( c ),
00026 profil( pf ),
00027 axis( v ),
00028 pas( p )
00029 {
00030
00031 if ( name == NULL ) {
00032 strcpy(name, G_defaultname);
00033
00034 } else {
00035 strcpy(name, name);
00036 }
00037
00038 }
00039
00040 int AxisCAO::GenerateArc( FILE* f )
00041 {
00042 numerotation* n = AllocNumerotation();
00043 int error;
00044
00045 if ( fprintf ( f, "%u\n", n->CardinalArc() ) == EOF )
00046 return (globalresult.error = MOD_SOM_ERROR_BAD_FIC_WRITE );
00047
00048 if ( (error = numerotation::NumArc( *n, f ) ) != SUCCESS )
00049 return globalresult.error =error;
00050
00051 globalresult.cardarc = n->CardinalArc();
00052
00053 delete n;
00054
00055 return SUCCESS;
00056 }
00057
00058 int AxisCAO::GenerateFace( FILE* f )
00059 {
00060 numerotation* n = AllocNumerotation();
00061 int error;
00062
00063 if ( fprintf ( f, "%u\n", n->CardinalFace() ) == EOF )
00064 return globalresult.error =MOD_SOM_ERROR_BAD_FIC_WRITE;
00065
00066 if ( (error = numerotation::NumFace(*n, f ) ) != SUCCESS )
00067 return globalresult.error =error;
00068
00069 globalresult.cardface = n->CardinalFace();
00070
00071 delete n;
00072
00073 return SUCCESS;
00074 }
00075
00076
00077 int RotProfToProfAxisCAO::GenerateVertex( FILE* f )
00078 {
00079 int error;
00080 Sommet3D* tbl;
00081 UINT card;
00082
00083 realtype sinalpha, cosalpha,
00084 sinbeta, cosbeta,
00085 lgr, x, y, z;
00086
00087 x = axis.b.x - axis.a.x;
00088 y = axis.b.y - axis.a.y;
00089 z = axis.b.z - axis.a.z;
00090 lgr = sqrt( x*x + y*y + z*z );
00091
00092
00093
00094 cosalpha = (z == 0)?(0):(lgr/z);
00095 sinalpha = sqrt( 1 - (cosalpha*cosalpha) );
00096 cosbeta = (x == 0)?(0):(lgr/x);
00097 sinbeta = sqrt( 1-(cosbeta*cosbeta));
00098
00099
00100
00101
00102 for( UINT i = 0; i != cardprofil; i++ ) {
00103 TransVertex ( profil+i, -axis.a.x, -axis.a.y, -axis.a.z );
00104 RotateVertex( profil+i, cosbeta, sinbeta, Z_AXIS );
00105 RotateVertex( profil+i, cosalpha, -sinalpha, Y_AXIS );
00106 };
00107
00108
00109
00110 if ( ( error = ModeleurRotationZ(
00111 profil,
00112 profil1,
00113 (UINT) cardprofil,
00114 &tbl,
00115 &card,
00116 &(globalresult.type),
00117 angle,
00118 pas
00119
00120 ) ) != SUCCESS ) return globalresult.error =error;
00121
00122
00123
00124
00125
00126 for ( i = 0; i != card; i++ )
00127 {
00128 RotateVertex( tbl+i, cosalpha, sinalpha, Y_AXIS );
00129 RotateVertex( tbl+i, cosbeta, -sinbeta, Z_AXIS );
00130 TransVertex ( tbl+i, axis.a.x, axis.a.y, axis.a.z );
00131 }
00132 for ( i = 0; i != cardprofil; i++ )
00133 {
00134 RotateVertex( profil+i, cosalpha, sinalpha, Y_AXIS );
00135 RotateVertex( profil+i, cosbeta, -sinbeta, Z_AXIS );
00136 TransVertex ( profil+i, axis.a.x, axis.a.y, axis.a.z );
00137 }
00138
00139
00140
00141 BoiteLim bl;
00142 SetBoiteLimite( tbl, card,&bl );
00143
00144
00145
00146 if ( fprintf ( f, "%f %f %f %f %f %f\n%u\n", bl.S1.x,
00147 bl.S1.y,
00148 bl.S1.z,
00149 bl.S2.x,
00150 bl.S2.y,
00151 bl.S2.z,
00152 card ) == EOF )
00153 return globalresult.error =MOD_SOM_ERROR_BAD_FIC_WRITE;
00154
00155 for ( i = 0; i != card; i++ )
00156 if ( fprintf ( f, "%lf %lf %lf\n", tbl[i].x,
00157 tbl[i].y,
00158 tbl[i].z ) == EOF )
00159 return globalresult.error =MOD_SOM_ERROR_BAD_FIC_WRITE;
00160
00161 fprintf ( f, "\n" );
00162
00163
00164
00165 globalresult.cardsommet = card;
00166
00167 return SUCCESS; }
00168
00169 numerotation* RotProfToProfAxisCAO::AllocNumerotation()
00170 {
00171 if ( globalresult.type.phor == HOR_CLOSE )
00172 {
00173 if ( globalresult.type.pvert == VERT_OPEN )
00174 switch ( globalresult.type.ponaxis )
00175 {
00176 case EXTR_BOTH : return new FermeOuvertOnAxisBoth(pas-1,cardprofil-1);
00177 case EXTR_SUP : return new FermeOuvertOnAxisSup(pas-1,cardprofil-1);
00178 case EXTR_INF : return new FermeOuvertOnAxisInf(pas-1,cardprofil-1);
00179 default : return new FermeOuvert(pas-1,cardprofil-1) ;
00180 }
00181 return new FermeFerme(pas-1,cardprofil-2);
00182
00183 }
00184
00185 if ( globalresult.type.pvert == VERT_CLOSE )
00186 return new OuvertFerme(pas-1,cardprofil-2);
00187
00188 switch ( globalresult.type.ponaxis )
00189 {
00190 case EXTR_BOTH : return new OuvertOuvertOnAxisBoth(pas-1,cardprofil-1);
00191 case EXTR_SUP : return new OuvertOuvertOnAxisSup(pas-1,cardprofil-1);
00192 case EXTR_INF : return new OuvertOuvertOnAxisInf(pas-1,cardprofil-1);
00193 default : return new OuvertOuvert(pas-1,cardprofil-1) ;
00194 }
00195 }
00196
00197
00198 int ProfToProfAxisCAO::GenerateVertex( FILE* f ) {
00199 int error;
00200 Sommet3D* tbl;
00201 UINT card;
00202
00203
00204
00205 if ( ( error = ModeleurProfToProf( profil,
00206 profil1,
00207 (UINT) cardprofil,
00208 &tbl,
00209 &card,
00210 &(globalresult.type),
00211 axis,
00212 pas
00213
00214 ) ) != SUCCESS ) return globalresult.error = error;
00215
00216
00217
00218 BoiteLim bl;
00219 SetBoiteLimite( tbl, card,&bl );
00220
00221
00222
00223 if ( fprintf ( f, "%f %f %f %f %f %f\n%u\n", bl.S1.x,
00224 bl.S1.y,
00225 bl.S1.z,
00226 bl.S2.x,
00227 bl.S2.y,
00228 bl.S2.z,
00229 card ) == EOF )
00230 return globalresult.error =MOD_SOM_ERROR_BAD_FIC_WRITE;
00231
00232 for ( UINT i = 0; i != card; i ++ )
00233 if ( fprintf ( f, "%lf %lf %lf\n", tbl[i].x,
00234 tbl[i].y,
00235 tbl[i].z ) == EOF )
00236 return globalresult.error =MOD_SOM_ERROR_BAD_FIC_WRITE;
00237
00238 fprintf ( f, "\n" );
00239
00240
00241
00242 globalresult.cardsommet = card;
00243
00244 return SUCCESS; }
00245
00246
00247 numerotation* ProfToProfAxisCAO::AllocNumerotation()
00248 {
00249 if ( globalresult.type.pvert == VERT_CLOSE )
00250 return new OuvertFerme(pas-1,cardprofil-2);
00251
00252 return new OuvertOuvert(pas-1,cardprofil-1);
00253 }
00254
00255
00256 int VecAxisCAO::GenerateVertex( FILE* f )
00257 { int error;
00258 Sommet3D* tbl;
00259 UINT card;
00260
00261
00262
00263 if ( ( error = ModeleurVector ( profil,
00264 (UINT ) cardprofil,
00265 &tbl,
00266 &card,
00267 &(globalresult.type),
00268 vectbl,
00269 pas )
00270 ) != SUCCESS )
00271 return globalresult.error =error;
00272
00273
00274
00275 BoiteLim bl;
00276 SetBoiteLimite( tbl, card,&bl );
00277
00278
00279
00280 if ( fprintf ( f, "%f %f %f %f %f %f\n%u\n", bl.S1.x,
00281 bl.S1.y,
00282 bl.S1.z,
00283 bl.S2.x,
00284 bl.S2.y,
00285 bl.S2.z,
00286 card ) == EOF )
00287 return globalresult.error =MOD_SOM_ERROR_BAD_FIC_WRITE;
00288
00289 for ( UINT i = 0; i != card; i ++ )
00290 if ( fprintf ( f, "%lf %lf %lf\n", tbl[i].x,
00291 tbl[i].y,
00292 tbl[i].z ) == EOF )
00293 return globalresult.error =MOD_SOM_ERROR_BAD_FIC_WRITE;
00294
00295 fprintf ( f, "\n" );
00296
00297
00298
00299 globalresult.cardsommet = card;
00300
00301 return SUCCESS;
00302 }
00303
00304
00305 numerotation* VecAxisCAO::AllocNumerotation()
00306 {
00307 if ( globalresult.type.pvert == VERT_CLOSE )
00308 return new OuvertFerme(pas-1,cardprofil-2);
00309
00310 return new OuvertOuvert(pas-1,cardprofil-1);
00311 }
00312
00313
00314 int Generate ( AxisCAO& m )
00315 { int error;
00316 char ficname[15];
00317
00318
00319 FILE* f = fopen( strcat(strcpy(ficname,m.name),ShapeExt), "w" );
00320 if ( !f ) return MOD_GENERATE_ERROR_OPEN_FIC;
00321
00322 if ( (error = m.GenerateVertex(f)) != SUCCESS )
00323 { fclose(f); return error; }
00324
00325 if ( (error = m.GenerateArc(f)) != SUCCESS )
00326 { fclose(f); return error; }
00327
00328 if ( (error = m.GenerateFace(f)) != SUCCESS )
00329 { fclose(f); return error; }
00330
00331 fclose(f);
00332
00333 return SUCCESS;
00334 }
00335
00336 char* RotProfToProfAxisCAO::GetErrorMsg() {
00337 if ( globalresult.error >= __ReservedMsg)
00338 return G_modetbmsg[ globalresult.error - __ReservedMsg ];
00339 return GetModelRotatErrorMsg( globalresult.error );
00340 }
00341
00342 char* ProfToProfAxisCAO::GetErrorMsg() {
00343 if ( globalresult.error >= __ReservedMsg)
00344 return G_modetbmsg[ globalresult.error - __ReservedMsg ];
00345 return GetModelProfToProfErrorMsg( globalresult.error );
00346 }
00347
00348 char* VecAxisCAO::GetErrorMsg() {
00349 if ( globalresult.error >= __ReservedMsg)
00350 return G_modetbmsg[ globalresult.error - __ReservedMsg ];
00351 return GetModelVectorErrorMsg( globalresult.error );
00352 }
00353