Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

vtk3DSOurImporter Class Reference

#include <vtk3DSOurImporter.h>

List of all members.

Public Member Functions

void SetPolys (char *f)
 vtkTypeMacro (vtk3DSOurImporter, vtkImporter)
void PrintSelf (ostream &os, vtkIndent indent)
 vtkSetStringMacro (FileName)
 vtkGetStringMacro (FileName)
 vtkSetMacro (ComputeNormals, int)
 vtkGetMacro (ComputeNormals, int)
 vtkBooleanMacro (ComputeNormals, int)
FILE * GetFileFD ()

Static Public Member Functions

vtk3DSOurImporterNew ()

Public Attributes

vtk3DSOmniLight * OmniList
vtk3DSSpotLight * SpotLightList
vtk3DSCamera * CameraList
vtk3DSMesh * MeshList
vtk3DSMaterial * MaterialList
vtk3DSMatProp * MatPropList

Protected Member Functions

 vtk3DSOurImporter ()
 ~vtk3DSOurImporter ()
virtual int ImportBegin ()
virtual void ImportEnd ()
virtual void ImportActors (vtkRenderer *renderer)
virtual void ImportCameras (vtkRenderer *renderer)
virtual void ImportLights (vtkRenderer *renderer)
virtual void ImportProperties (vtkRenderer *renderer)
vtkPolyData * GeneratePolyData (vtk3DSMesh *meshPtr)
int Read3DS ()

Protected Attributes

char * FileName
FILE * FileFD
int ComputeNormals
int flag3

Private Member Functions

 vtk3DSOurImporter (const vtk3DSOurImporter &)
void operator= (const vtk3DSOurImporter &)


Constructor & Destructor Documentation

vtk3DSOurImporter::vtk3DSOurImporter  )  [protected]
 

Definition at line 131 of file vtk3DSOurImporter.cpp.

References CameraList, ComputeNormals, FileFD, FileName, flag3, MaterialList, MatPropList, MeshList, OmniList, and SpotLightList.

00132 {
00133   this->OmniList = NULL;
00134   this->SpotLightList = NULL;
00135   this->CameraList = NULL;
00136   this->MeshList = NULL;
00137   this->MaterialList = NULL;
00138   this->MatPropList = NULL;
00139   this->FileName = NULL;
00140   this->FileFD = NULL;
00141   this->ComputeNormals = 0;
00142   this->flag3 = 0;
00143 }

vtk3DSOurImporter::~vtk3DSOurImporter  )  [protected]
 

Definition at line 1236 of file vtk3DSOurImporter.cpp.

References CameraList, FileName, MatPropList, MeshList, OmniList, and SpotLightList.

01237 {
01238   vtk3DSOmniLight *omniLight;
01239   vtk3DSSpotLight *spotLight;
01240 
01241   // walk the light list and delete vtk objects
01242   for (omniLight = this->OmniList; omniLight != (vtk3DSOmniLight *) NULL; omniLight = (vtk3DSOmniLight *) omniLight->next)
01243     {
01244     omniLight->aLight->Delete();
01245     }
01246   VTK_LIST_KILL (this->OmniList);
01247 
01248   // walk the spot light list and delete vtk objects
01249   for (spotLight = this->SpotLightList; spotLight != (vtk3DSSpotLight *) NULL; 
01250        spotLight = (vtk3DSSpotLight *) spotLight->next)
01251     {
01252     spotLight->aLight->Delete();
01253     }
01254   VTK_LIST_KILL (this->SpotLightList);
01255 
01256   vtk3DSCamera *camera;
01257   // walk the camera list and delete vtk objects
01258   for (camera = this->CameraList; camera != (vtk3DSCamera *) NULL; 
01259        camera = (vtk3DSCamera *) camera->next)
01260     {
01261     camera->aCamera->Delete ();
01262     }
01263   VTK_LIST_KILL (this->CameraList);
01264 
01265   // walk the mesh list and delete malloced datra and vtk objects
01266   vtk3DSMesh *mesh;
01267   for (mesh = this->MeshList; mesh != (vtk3DSMesh *) NULL; 
01268        mesh = (vtk3DSMesh *) mesh->next)
01269     {
01270     if (mesh->anActor != NULL)
01271       {
01272       mesh->anActor->Delete ();
01273       }
01274     if (mesh->aMapper != NULL)
01275       {
01276       mesh->aMapper->Delete ();
01277       }
01278     if (mesh->aNormals != NULL)
01279       {
01280       mesh->aNormals->Delete ();
01281       }
01282     if (mesh->aStripper != NULL)
01283       {
01284       mesh->aStripper->Delete ();
01285       }
01286     if (mesh->aPoints != NULL)
01287       {
01288       mesh->aPoints->Delete ();
01289       }
01290     if (mesh->aCellArray != NULL)
01291       {
01292       mesh->aCellArray->Delete ();
01293       }
01294     if (mesh->aPolyData != NULL)
01295       {
01296       mesh->aPolyData->Delete ();
01297       }
01298     if (mesh->vertex)
01299       {
01300       free (mesh->vertex);
01301       }
01302     if (mesh->face)
01303       {
01304       free (mesh->face);
01305       }
01306     if (mesh->mtl)
01307       {
01308       free (mesh->mtl);  
01309       }
01310     }
01311 
01312   // then delete the list structure
01313 
01314   VTK_LIST_KILL (this->MeshList);
01315   VTK_LIST_KILL (this->MaterialList);
01316 
01317   // objects allocated in Material Property List
01318   vtk3DSMatProp *m;
01319   // just walk the list of material properties, deleting vtk properties
01320   for (m = this->MatPropList; m != (vtk3DSMatProp *) NULL; m = (vtk3DSMatProp *) m->next)
01321     {
01322     m->aProperty->Delete();
01323     }
01324 
01325   // then delete the list structure
01326   VTK_LIST_KILL (this->MatPropList);
01327 
01328   if (this->FileName)
01329     {
01330     delete [] this->FileName;
01331     }
01332 }

vtk3DSOurImporter::vtk3DSOurImporter const vtk3DSOurImporter  )  [private]
 


Member Function Documentation

vtkPolyData * vtk3DSOurImporter::GeneratePolyData vtk3DSMesh *  meshPtr  )  [protected]
 

Definition at line 239 of file vtk3DSOurImporter.cpp.

References flag3.

Referenced by ImportActors().

00240 {
00241   int i;
00242   vtk3DSFace  *face;
00243   vtkCellArray *triangles;
00244   vtkPoints *vertices;
00245   vtkPolyData *polyData;
00246 
00247   face = mesh->face;
00248   mesh->aCellArray = triangles = vtkCellArray::New ();
00249   triangles->Allocate(mesh->faces * 4);
00250  
00251   if (flag3!=0) 
00252   for (i = 0; i < mesh->faces; i++, face++)
00253     {
00254     triangles->InsertNextCell (4);
00255     triangles->InsertCellPoint (face->a);
00256     triangles->InsertCellPoint (face->b);
00257     triangles->InsertCellPoint (face->c);
00258     i++; face++;
00259     triangles->InsertCellPoint (face->b);
00260     }
00261   else
00262   for (i = 0; i < mesh->faces; i++, face++)
00263     {
00264     triangles->InsertNextCell (3);
00265     triangles->InsertCellPoint (face->a);
00266     triangles->InsertCellPoint (face->b);
00267     triangles->InsertCellPoint (face->c);
00268     }
00269 
00270   mesh->aPoints = vertices = vtkPoints::New ();
00271   vertices->Allocate(mesh->vertices);
00272   for (i = 0; i < mesh->vertices; i++)
00273     {
00274     vertices->InsertPoint (i, (float *) mesh->vertex[i]);
00275     }
00276   mesh->aPolyData = polyData = vtkPolyData::New ();
00277   polyData->SetPolys (triangles);
00278   polyData->SetPoints (vertices);
00279 
00280   return polyData;
00281 }

FILE* vtk3DSOurImporter::GetFileFD  )  [inline]
 

Definition at line 81 of file vtk3DSOurImporter.h.

Referenced by end_chunk(), read_byte(), read_dword(), read_float(), read_word(), and start_chunk().

00081 {return this->FileFD;};

void vtk3DSOurImporter::ImportActors vtkRenderer *  renderer  )  [protected, virtual]
 

Definition at line 186 of file vtk3DSOurImporter.cpp.

References ComputeNormals, GeneratePolyData(), and MeshList.

00187 {
00188   vtk3DSMatProp *material;
00189   vtk3DSMesh *mesh;
00190   vtkStripper *polyStripper;
00191   vtkPolyDataNormals *polyNormals;
00192   vtkPolyDataMapper *polyMapper;
00193   vtkPolyData *polyData;
00194   vtkActor *actor;
00195 
00196   // walk the list of meshes, creating actors
00197   for (mesh = this->MeshList; mesh != (vtk3DSMesh *) NULL; 
00198        mesh = (vtk3DSMesh *) mesh->next)
00199     {
00200     if (mesh->faces == 0)
00201       {
00202       vtkWarningMacro (<< "part " << mesh->name << " has zero faces... skipping\n");
00203       continue;
00204       }
00205 
00206     polyData = this->GeneratePolyData (mesh);
00207     mesh->aMapper = polyMapper = vtkPolyDataMapper::New ();
00208     mesh->aStripper = polyStripper = vtkStripper::New ();
00209 
00210     // if ComputeNormals is on, insert a vtkPolyDataNormals filter
00211     if (this->ComputeNormals)
00212       {
00213       mesh->aNormals = polyNormals = vtkPolyDataNormals::New ();
00214       polyNormals->SetInput (polyData);
00215       polyStripper->SetInput (polyNormals->GetOutput ());
00216       }
00217     else
00218       {
00219         polyStripper->SetInput (polyData);
00220       }
00221     
00222     //polyMapper->SetInput (polyStripper->GetOutput ());
00223     polyMapper->SetInput(polyData);
00224     vtkDebugMacro (<< "Importing Actor: " << mesh->name);
00225     mesh->anActor = actor = vtkActor::New ();
00226     actor->SetMapper (polyMapper);
00227     material = (vtk3DSMatProp *)VTK_LIST_FIND(this->MatPropList, mesh->mtl[0]->name);
00228     actor->SetProperty (material->aProperty);
00229     renderer->AddActor (actor);
00230   }
00231 }

Here is the call graph for this function:

int vtk3DSOurImporter::ImportBegin  )  [protected, virtual]
 

Definition at line 145 of file vtk3DSOurImporter.cpp.

References FileFD, and Read3DS().

00146 {
00147   vtkDebugMacro(<< "Opening import file as binary");
00148   this->FileFD = fopen (this->FileName, "rb");
00149   if (this->FileFD == NULL)
00150     {
00151     vtkErrorMacro(<< "Unable to open file: "<< this->FileName);
00152     return 0;
00153     }
00154   return this->Read3DS ();
00155 }

Here is the call graph for this function:

void vtk3DSOurImporter::ImportCameras vtkRenderer *  renderer  )  [protected, virtual]
 

Definition at line 283 of file vtk3DSOurImporter.cpp.

References CameraList.

00284 {
00285   vtkCamera *aCamera;
00286   vtk3DSCamera *camera;
00287 
00288   // walk the list of cameras and create vtk cameras
00289   for (camera = this->CameraList; camera != (vtk3DSCamera *) NULL; camera = (vtk3DSCamera *) camera->next)
00290     {
00291     camera->aCamera = aCamera = vtkCamera::New ();      
00292     aCamera->SetPosition (camera->pos[0], camera->pos[1], camera->pos[2]);
00293     aCamera->SetFocalPoint (camera->target[0], camera->target[1], camera->target[2]);
00294     aCamera->SetViewUp (0, 0, 1);
00295     aCamera->SetClippingRange (.1,10000);
00296     aCamera->Roll (camera->bank);
00297     renderer->SetActiveCamera (aCamera);
00298     vtkDebugMacro (<< "Importing Camera: " << camera->name);
00299   }
00300 }

void vtk3DSOurImporter::ImportEnd  )  [protected, virtual]
 

Definition at line 157 of file vtk3DSOurImporter.cpp.

References FileFD.

00158 {
00159   vtkDebugMacro(<<"Closing import file");
00160   if ( this->FileFD != NULL )
00161     {
00162     fclose (this->FileFD);
00163     }
00164   this->FileFD = NULL;
00165 }

void vtk3DSOurImporter::ImportLights vtkRenderer *  renderer  )  [protected, virtual]
 

Definition at line 302 of file vtk3DSOurImporter.cpp.

References OmniList, and SpotLightList.

00303 {
00304   vtk3DSOmniLight *omniLight;
00305   vtk3DSSpotLight *spotLight;
00306   vtkLight *aLight;
00307 
00308   // just walk the list of omni lights, creating vtk lights
00309   for (omniLight = this->OmniList; omniLight != (vtk3DSOmniLight *) NULL; 
00310        omniLight = (vtk3DSOmniLight *) omniLight->next)
00311   {
00312   omniLight->aLight = aLight = vtkLight::New ();
00313   aLight->SetPosition (omniLight->pos[0],
00314                        omniLight->pos[1],
00315                        omniLight->pos[2]);
00316   aLight->SetFocalPoint (0, 0, 0);
00317   aLight->SetColor (omniLight->col.red,
00318                     omniLight->col.green,
00319                     omniLight->col.blue);
00320   renderer->AddLight (aLight);
00321   vtkDebugMacro (<< "Importing Omni Light: " << omniLight->name);
00322   }                       
00323 
00324   // now walk the list of spot lights, creating vtk lights
00325   for (spotLight = this->SpotLightList; spotLight != (vtk3DSSpotLight *) NULL; 
00326        spotLight = (vtk3DSSpotLight *) spotLight->next)
00327   {
00328   spotLight->aLight = aLight = vtkLight::New ();
00329   aLight->PositionalOn ();
00330   aLight->SetPosition (spotLight->pos[0],
00331                        spotLight->pos[1],
00332                        spotLight->pos[2]);
00333   aLight->SetFocalPoint (spotLight->target[0],
00334                          spotLight->target[1],
00335                          spotLight->target[2]);
00336   aLight->SetColor (spotLight->col.red,
00337                     spotLight->col.green,
00338                     spotLight->col.blue);
00339   aLight->SetConeAngle (spotLight->falloff);
00340   renderer->AddLight (aLight);
00341   vtkDebugMacro (<< "Importing Spot Light: " << spotLight->name);
00342   }                       
00343 }

virtual void vtk3DSOurImporter::ImportProperties vtkRenderer *  renderer  )  [protected, virtual]
 

vtk3DSOurImporter * vtk3DSOurImporter::New  )  [static]
 

Definition at line 57 of file vtk3DSOurImporter.cpp.

Referenced by MainWindow::newSubdivision().

00058 {
00059   // First try to create the object from the vtkObjectFactory
00060   vtkObject* ret = vtkObjectFactory::CreateInstance("vtk3DSOurImporter");
00061   if(ret)
00062     {
00063     return (vtk3DSOurImporter*)ret;
00064     }
00065   // If the factory was unable to create the object, then create it here.
00066   return new vtk3DSOurImporter;
00067 }

void vtk3DSOurImporter::operator= const vtk3DSOurImporter  )  [private]
 

void vtk3DSOurImporter::PrintSelf ostream &  os,
vtkIndent  indent
 

Definition at line 1334 of file vtk3DSOurImporter.cpp.

References ComputeNormals, and FileName.

01335 {
01336   vtkImporter::PrintSelf(os,indent);
01337   os << indent << "File Name: " 
01338      << (this->FileName ? this->FileName : "(none)") << "\n";
01339 
01340   os << indent << "Compute Normals: " 
01341      << (this->ComputeNormals ? "On\n" : "Off\n");
01342 }

int vtk3DSOurImporter::Read3DS  )  [protected]
 

Definition at line 167 of file vtk3DSOurImporter.cpp.

References DefaultMaterial, and parse_3ds_file().

Referenced by ImportBegin().

00168 {
00169   vtk3DSMatProp *aMaterial;
00170 
00171   if (parse_3ds_file (this) == 0)
00172     {
00173     vtkErrorMacro (<<  "Error readings .3ds file: " << this->FileName << "\n");
00174     return 0;
00175     }
00176 
00177 
00178   // create a MatProp and fill if in with default
00179   aMaterial = (vtk3DSMatProp *) malloc (sizeof (vtk3DSMatProp));
00180   *aMaterial = DefaultMaterial;
00181   aMaterial->aProperty = vtkProperty::New ();
00182   VTK_LIST_INSERT (this->MatPropList, aMaterial);
00183   return 1;
00184 }

Here is the call graph for this function:

void vtk3DSOurImporter::SetPolys char *  f  ) 
 

Definition at line 233 of file vtk3DSOurImporter.cpp.

References flag3.

Referenced by MainWindow::newSubdivision().

00234   {
00235   if (strcmp(f,"triangle")==0) flag3=0;
00236   else flag3=1;
00237   }

vtk3DSOurImporter::vtkBooleanMacro ComputeNormals  ,
int 
 

vtk3DSOurImporter::vtkGetMacro ComputeNormals  ,
int 
 

vtk3DSOurImporter::vtkGetStringMacro FileName   ) 
 

vtk3DSOurImporter::vtkSetMacro ComputeNormals  ,
int 
 

vtk3DSOurImporter::vtkSetStringMacro FileName   ) 
 

vtk3DSOurImporter::vtkTypeMacro vtk3DSOurImporter  ,
vtkImporter 
 


Member Data Documentation

vtk3DSCamera* vtk3DSOurImporter::CameraList
 

Definition at line 85 of file vtk3DSOurImporter.h.

Referenced by ImportCameras(), parse_n_camera(), vtk3DSOurImporter(), and ~vtk3DSOurImporter().

int vtk3DSOurImporter::ComputeNormals [protected]
 

Definition at line 105 of file vtk3DSOurImporter.h.

Referenced by ImportActors(), PrintSelf(), and vtk3DSOurImporter().

FILE* vtk3DSOurImporter::FileFD [protected]
 

Definition at line 104 of file vtk3DSOurImporter.h.

Referenced by ImportBegin(), ImportEnd(), and vtk3DSOurImporter().

char* vtk3DSOurImporter::FileName [protected]
 

Definition at line 103 of file vtk3DSOurImporter.h.

Referenced by PrintSelf(), vtk3DSOurImporter(), and ~vtk3DSOurImporter().

int vtk3DSOurImporter::flag3 [protected]
 

Definition at line 106 of file vtk3DSOurImporter.h.

Referenced by GeneratePolyData(), SetPolys(), and vtk3DSOurImporter().

vtk3DSMaterial* vtk3DSOurImporter::MaterialList
 

Definition at line 87 of file vtk3DSOurImporter.h.

Referenced by update_materials(), and vtk3DSOurImporter().

vtk3DSMatProp* vtk3DSOurImporter::MatPropList
 

Definition at line 88 of file vtk3DSOurImporter.h.

Referenced by parse_mat_entry(), vtk3DSOurImporter(), and ~vtk3DSOurImporter().

vtk3DSMesh* vtk3DSOurImporter::MeshList
 

Definition at line 86 of file vtk3DSOurImporter.h.

Referenced by ImportActors(), parse_n_tri_object(), vtk3DSOurImporter(), and ~vtk3DSOurImporter().

vtk3DSOmniLight* vtk3DSOurImporter::OmniList
 

Definition at line 83 of file vtk3DSOurImporter.h.

Referenced by ImportLights(), parse_n_direct_light(), vtk3DSOurImporter(), and ~vtk3DSOurImporter().

vtk3DSSpotLight* vtk3DSOurImporter::SpotLightList
 

Definition at line 84 of file vtk3DSOurImporter.h.

Referenced by ImportLights(), parse_n_direct_light(), vtk3DSOurImporter(), and ~vtk3DSOurImporter().


The documentation for this class was generated from the following files:
Generated on Sun Jun 22 12:13:19 2003 for Catmull Clark by doxygen 1.3.2