C:/cmcintos/defOrgs/examples/DefOrgViewer/Source/DefOrgViewer.cxx

00001 #include "DefOrgViewer.h"
00002 
00003 //class pickCallback
00004 //      : public vtkCommand
00005 //{
00006 //public:
00007 //      static pickCallback *New() { return new pickCallback; }
00008 //      void Delete() { delete this; }
00009 //
00010 //      void Execute(vtkObject *caller, 
00011 //              unsigned long event, 
00012 //              void *vtkNotUsed(callData))
00013 //      {
00014 //              vtkPointPicker* p = reinterpret_cast<vtkPointPicker*>(caller);
00015 //
00016 //              double positions[3];
00017 //
00018 //              p->GetPickPosition(positions);
00019 //              std::cout << "[" << positions[1] << ", " << positions[2] << ", " << positions[3] << "]" << std::endl;
00020 //              return;
00021 //      }
00022 //      float x, y, z;
00023 //};
00024 
00025 // Default constructor:
00026 DefOrgViewer
00027 ::DefOrgViewer()
00028 : DefOrgViewerGUI()
00029 {
00030         orgNotSet = true;
00031         geomLayerPointer = new GeometricType();
00032         mainWindow->show();
00033         display->show();
00034 
00035         isVolumeRenderingOn = false;
00036 
00037         scheduleFileName =              "data\\testSchedule3d.txt"; // TODO: eliminate hardcoded values here
00038 
00039         // note: from DefOrgViewer.h: 'renderer' is of type vtkRenderer*
00040         renderer = RendererType::New();
00041         renderer->SetBackground(0.0, 0.0, 0.0);
00042 
00043         renderWindow = vtkRenderWindow::New();
00044         renderWindow->AddRenderer( renderer );
00045 
00046         // note: 'display' is of type vtkFlRenderWindowInteractor*
00047         display->SetRenderWindow( renderWindow );
00048 
00049         image = NULL;
00050 
00051         planeX = vtkImagePlaneWidget::New();
00052         //planeX->RestrictPlaneToVolumeOn();
00053         //planeX->SetResliceInterpolateToCubic();
00054         //planeX->SetInput( static_cast<vtkDataSet*>(vtkImporter->GetOutput()) );
00055         //planeX->SetPlaneOrientationToXAxes();
00056         //planeX->SetSliceIndex( floor(static_cast<double>(imageSize[0]/2)) );
00057         //planeX->SetInteractor( display );
00058 
00059         opacityTransferFunction =       vtkPiecewiseFunction::New();
00060         colorTransferFunction =         vtkColorTransferFunction::New();
00061         compositeFunction =                     vtkVolumeRayCastCompositeFunction::New();
00062         volumeProperty =                        vtkVolumeProperty::New();
00063         volumeMapper =                          vtkVolumeRayCastMapper::New();
00064 
00065         //opacityTransferFunction->AddPoint( 20,                2 );
00066         //opacityTransferFunction->AddPoint( 255,               0.2 );
00067         opacityTransferFunction->AddPoint( 20,          0.7 );
00068         opacityTransferFunction->AddPoint( 255,         1.0 );
00069         opacityTransferFunction->AddSegment( 100, 0.8, 150, 0.2 );
00070 
00071         colorTransferFunction->AddRGBPoint( 0.0,        0.0,    0.0,    0.0 );
00072         colorTransferFunction->AddRGBPoint( 64.0,       1.0,    0.0,    0.0 );
00073         colorTransferFunction->AddRGBPoint( 128.0,      0.0,    0.0,    1.0 );
00074         //colorTransferFunction->AddRGBPoint( 255.0,    0.0,    0.2,    0.0 );
00075         colorTransferFunction->AddRGBPoint( 255.0,      255.0,  255.0,  255.0 );
00076         //colorTransferFunction->AddRGBPoint( 255.0,    1.0,    1.0,    1.0 );
00077         
00078     //compositeFunction->SetCompositeMethodToInterpolateFirst();
00079 
00080         volumeProperty->SetColor(                       colorTransferFunction );
00081         volumeProperty->SetScalarOpacity(       opacityTransferFunction );
00082         volumeProperty->SetInterpolationTypeToLinear();
00083 
00084         //compositeFunction = vtkVolumeRayCastMIPFunction::New();
00085 
00086         volumeMapper->SetVolumeRayCastFunction( compositeFunction );
00087         //volumeMapper->SetInput( vtkImporter->GetOutput() );
00088         
00089         volume = vtkVolume::New();
00090         volume->SetMapper( volumeMapper );
00091         volume->SetProperty( volumeProperty );
00092 
00093         meshMapper = vtkDataSetMapper::New();
00094 
00095         axes = vtkCubeAxesActor2D::New();
00096         
00097         display->Initialize();
00098 
00099         //renderWindow->Render();
00100 
00101         return;
00102 }
00103 
00104 // Constructor:
00105 DefOrgViewer
00106 ::DefOrgViewer( MeshTypePointer itkMesh )
00107 {
00108         orgNotSet=true;
00109         geomLayerPointer = new GeometricType();
00110         mainWindow->show();
00111         display->show();
00112 
00113         // note: from DefOrgViewer.h: 'renderer' is of type vtkRenderer*
00114         renderer = RendererType::New();
00115         renderer->SetBackground(0.0, 0.0, 0.0);
00116 
00117         renderWindow = vtkRenderWindow::New();
00118         renderWindow->AddRenderer( renderer );
00119 
00120         // note: 'display' is of type vtkFlRenderWindowInteractor*
00121         display->SetRenderWindow( renderWindow );
00122 
00123         //-----------------------------------------------------------------------
00124         // DEBUG: TEST USING SPHERE MESH SOURCE
00125         //typedef itk::RegularSphereMeshSource< MeshType > SphereMeshSourceType;
00126         //SphereMeshSourceType::Pointer sphereMesh = SphereMeshSourceType::New();
00127 
00128         //SphereMeshSourceType::PointType centerPoint;
00129         //for( unsigned int i=0; i<N_DIMS; i++ )
00130         //{
00131         //      centerPoint[i] = 50.0;
00132         //}
00133 
00134         //sphereMesh->SetCenter( centerPoint );
00135         //sphereMesh->SetScale( 20 );
00136         //sphereMesh->SetResolution( 4 );
00137         //
00138         //sphereMesh->Update();
00139 
00140         //MeshType::Pointer myMesh = sphereMesh->GetOutput();
00142 
00143 
00144         // convert ITK mesh into VTK grid:
00145         //vtkUnstructuredGrid* vtkGrid = MeshToUnstructuredGrid( myMesh );
00146         vtkUnstructuredGrid* vtkGrid = MeshToUnstructuredGrid( itkMesh );
00147 
00148 
00149         //-----------------------------------------------------
00150         // Image stuff:
00151         typedef itk::ImageFileReader< ImageType > ImageReaderType;
00152         ImageReaderType::Pointer imageReader = ImageReaderType::New();
00153         itk::MetaImageIOFactory::RegisterOneFactory();
00154 
00155         char* inputImageFileName = fl_file_chooser("Pick an image file to load", "*.*", 0, 0);
00156 
00157         imageReader->SetFileName( inputImageFileName );
00158         //typedef itk::CastImageFilter< ImageType, ImageType >                  UCharCastFilterType;
00159         //UCharCastFilterType::Pointer castFilter = UCharCastFilterType::New();
00160         //castFilter->SetInput( imageReader->GetOutput() );
00161         //castFilter->Update();
00162 
00163         //image = castFilter->GetOutput();
00164         image = imageReader->GetOutput();
00165 
00166         //vtkJPEGReader* vtkImageReader = vtkJPEGReader::New();
00167         //vtkImageReader->SetFileName( "data\\baseball.jpg" );
00168         //vtkImageReader->Update();
00169 
00170         //vtkMetaImageReader* vtkMetaReader = vtkMetaImageReader::New();
00171         //vtkMetaReader->SetFileName( "data\\test.mhd" );
00172 
00173         itkExporter = itkImageExportType::New();
00174         itkExporter->SetInput( image );
00175 
00176         vtkImporter = vtkImageImportType::New();
00177 
00178         std::cout << "Starting to connect ITK pipeline->VTK pipeline..." << std::endl;
00179         ConnectPipelines( itkExporter, vtkImporter );
00180         std::cout << "Finished connecting ITK pipeline->VTK pipeline..." << std::endl;
00181 
00182         itkExporter->Update();
00183         vtkImporter->Update();
00184 
00185         //vtkJPEGWriter* vtkImageWriter = vtkJPEGWriter::New();
00186         //vtkImageWriter->SetFileName( "data\\VTK_TEST_WRITE.jpg" );
00187         //vtkImageWriter->SetInput( vtkImporter->GetOutput() );
00188         //try
00189         //{
00190         //      vtkImageWriter->Write();
00191         //}
00192         //catch( ... )
00193         //{
00194         //      std::cout << "Error writing VTK JPEG." << std::endl;
00195         //}
00196 
00197         itk::Size< N_DIMS > imageSize = image->GetLargestPossibleRegion().GetSize();
00198 
00199         vtkImagePlaneWidget* planeX = vtkImagePlaneWidget::New();
00200         planeX->RestrictPlaneToVolumeOn();
00201         planeX->SetResliceInterpolateToCubic();
00202         planeX->SetInput( static_cast<vtkDataSet*>(vtkImporter->GetOutput()) );
00203         planeX->SetPlaneOrientationToXAxes();
00204         planeX->SetSliceIndex( floor(static_cast<double>(imageSize[0]/2)) );
00205         planeX->SetInteractor( display );
00206 
00207         vtkImagePlaneWidget* planeY = vtkImagePlaneWidget::New();
00208         planeY->RestrictPlaneToVolumeOn();
00209         planeY->SetResliceInterpolateToCubic();
00210         planeY->SetInput( static_cast<vtkDataSet*>(vtkImporter->GetOutput()) );
00211         planeY->SetPlaneOrientationToYAxes();
00212         planeY->SetSliceIndex( floor(static_cast<double>(imageSize[1]/2)) );
00213         planeY->SetInteractor( display );
00214 
00215         vtkImagePlaneWidget* planeZ = vtkImagePlaneWidget::New();
00216         planeZ->RestrictPlaneToVolumeOn();
00217         planeZ->SetResliceInterpolateToCubic();
00218         planeZ->SetInput( static_cast<vtkDataSet*>(vtkImporter->GetOutput()) );
00219         planeZ->SetPlaneOrientationToZAxes();
00220         planeZ->SetSliceIndex( floor(static_cast<double>(imageSize[2]/2)) );
00221         planeZ->SetInteractor( display );
00222 
00223         //-----------------------------------------------------
00224         // DEBUG: VOLUME RENDERING TEST
00225         // note: declared in DefOrgViewer.h:
00226         //vtkPiecewiseFunction*                 opacityTransferFunction;
00227         //vtkColorTransferFunction*             colorTransferFunction;
00228         //vtkVolumeRayCastCompositeFunction* compositeFunction;
00229         //vtkVolumeProperty*                            volumeProperty;
00230         //vtkVolumeRayCastMapper*                       volumeMapper;
00231 
00232         opacityTransferFunction =       vtkPiecewiseFunction::New();
00233         colorTransferFunction =         vtkColorTransferFunction::New();
00234         compositeFunction =                     vtkVolumeRayCastCompositeFunction::New();
00235         volumeProperty =                        vtkVolumeProperty::New();
00236         volumeMapper =                          vtkVolumeRayCastMapper::New();
00237 
00238         //opacityTransferFunction->AddPoint( 20,                2 );
00239         //opacityTransferFunction->AddPoint( 255,               0.2 );
00240         //opacityTransferFunction->AddPoint( 20,                0.7 );
00241         //opacityTransferFunction->AddPoint( 255,               1.0 );
00242         opacityTransferFunction->AddSegment( 0, 0.2, 150, 0.8 );
00243 
00244         colorTransferFunction->AddRGBPoint( 0.0,        0.0,    0.0,    0.0 );
00245         colorTransferFunction->AddRGBPoint( 64.0,       1.0,    0.0,    0.0 );
00246         colorTransferFunction->AddRGBPoint( 128.0,      0.0,    0.0,    1.0 );
00247         //colorTransferFunction->AddRGBPoint( 255.0,    0.0,    0.2,    0.0 );
00248         colorTransferFunction->AddRGBPoint( 255.0,      255.0,  255.0,  255.0 );
00249         //colorTransferFunction->AddRGBPoint( 255.0,    1.0,    1.0,    1.0 );
00250         
00251     //compositeFunction->SetCompositeMethodToInterpolateFirst();
00252 
00253         volumeProperty->SetColor(                       colorTransferFunction );
00254         volumeProperty->SetScalarOpacity(       opacityTransferFunction );
00255         volumeProperty->SetInterpolationTypeToLinear();
00256 
00257         //compositeFunction = vtkVolumeRayCastMIPFunction::New();
00258 
00259         volumeMapper->SetVolumeRayCastFunction( compositeFunction );
00260         volumeMapper->SetInput( vtkImporter->GetOutput() );
00261         
00262         volume = vtkVolume::New();
00263         volume->SetMapper( volumeMapper );
00264         volume->SetProperty( volumeProperty );
00265         volume->VisibilityOn();
00266         
00267         renderer->AddVolume( volume );
00268 
00269         //vtkActor* volumeActor = vtkActor::New();
00270         //volumeActor->SetMapper( volumeMapper );
00271         //renderer->AddActor( volumeActor );
00272 
00273         //-----------------------------------------------------
00274         // DEBUG: IMPLICIT PLANE WIDGET TEST
00275 
00276         //vtkImplicitPlaneWidget* planeWidget = vtkImplicitPlaneWidget::New();
00277         //planeWidget->SetInteractor( display );
00278 
00279         //-----------------------------------------------------
00280 
00281         vtkDataSetMapper* mapper = vtkDataSetMapper::New();
00282         mapper->SetInput( vtkGrid );
00283         vtkActor* actor = vtkActor::New();
00284         actor->SetMapper( mapper );
00285 
00286         renderer->AddActor( actor );
00287         //renderer->AddActor( imgActor );
00288 
00289         planeX->On();
00290         planeY->On();
00291         planeZ->On();
00292 
00293         //trackBallInteractor = vtkInteractorStyleTrackballActor::New();
00294         //display->SetInteractorStyle( trackBallInteractor );
00295 
00296         display->Initialize();
00297 
00298         renderWindow->Render();
00299 
00300         return;
00301 }
00302 
00303 //void
00304 //DefOrgViewer
00305 //::ChangeRepresentation( )
00306 //{
00307 //
00308 //      /*      GroupType::ChildrenListPointer children = group->GetChildren();
00309 //      GroupType::ChildrenListType::iterator it = children->begin();
00310 //
00311 //      while( it != children->end() )
00312 //      {
00313 //      renderer->GetVisualObject(*it)->GetProperty()->SetRepresentationType( rep );
00314 //      it++;
00315 //      }
00316 //
00317 //      renderer->Update();
00318 //      display->Update();
00319 //      */   
00320 //      return;
00321 //}
00322 
00323 
00324 void
00325 DefOrgViewer
00326 ::Quit()
00327 {
00328         this->Hide();
00329         exit( 0 );
00330 }
00331 
00332 void
00333 DefOrgViewer
00334 ::Show()
00335 {
00336         mainWindow->show();
00337 }
00338 
00339 void
00340 DefOrgViewer
00341 ::Update()
00342 {
00343         //display->Update();
00344 }
00345 
00346 void
00347 DefOrgViewer
00348 ::LoadImage()
00349 {
00350         imageReader = ImageReaderType::New();
00351         //itk::MetaImageIOFactory::RegisterOneFactory();
00352 
00353         char* inputImageFileName = fl_file_chooser("Pick an image file to load", "*.mh*", 0, 0);
00354         if( inputImageFileName == NULL){ return; };
00355 
00356         imageReader->SetFileName( inputImageFileName );
00357 
00358         image = imageReader->GetOutput();
00359 
00360         itkExporter = itkImageExportType::New();
00361         itkExporter->SetInput( image );
00362 
00363         vtkImporter = vtkImageImportType::New();
00364 
00365         std::cout << "Starting to connect ITK pipeline->VTK pipeline..." << std::endl;
00366         ConnectPipelines( itkExporter, vtkImporter );
00367         std::cout << "Finished connecting ITK pipeline->VTK pipeline..." << std::endl;
00368 
00369         itkExporter->Update();
00370         vtkImporter->Update();
00371 
00372         itk::Size< N_DIMS > imageSize = image->GetLargestPossibleRegion().GetSize();
00373         planeX->RestrictPlaneToVolumeOn();
00374         planeX->SetInput( static_cast<vtkDataSet*>(vtkImporter->GetOutput()) );
00375         planeX->SetSliceIndex( floor(static_cast<double>( imageSize[2] / 2 )) );
00376         planeX->SetPlaneOrientationToZAxes();
00377         planeX->SetInteractor( display );
00378 
00379         planeX->On();
00380 
00381         volumeMapper->SetInput( vtkImporter->GetOutput() );
00382         isVolumeRenderingOn ? volume->VisibilityOn() : volume->VisibilityOff();
00383 
00384         renderer->AddVolume( volume );
00385         //camera = renderer->GetActiveCamera();
00386         //light = vtkLight::New();
00387         //light->SetColor( 1.0, 1.0, 1.0 ); // white light
00388         //light->SetFocalPoint( camera->GetFocalPoint() );
00389         //light->SetPosition( camera->GetPosition() );
00390         //renderer->AddLight( light );
00391         //double halfX, halfY, halfZ;
00392         //halfX = floor(static_cast<double>( imageSize[0] / 2 ));
00393         //halfY = floor(static_cast<double>( imageSize[1] / 2 ));
00394         //halfZ = floor(static_cast<double>( imageSize[2] / 2 ));
00395         //camera->SetFocalPoint( halfX, halfY, halfZ );
00396         //camera->SetPosition( halfX, halfY, -4*halfZ );
00397 
00398         axes->SetInput( vtkImporter->GetOutput() );
00399         axes->SetCamera( renderer->GetActiveCamera() );
00400         axes->SetLabelFormat( "%4.3g" );
00401         axes->SetFlyModeToOuterEdges();
00402         axes->SetFontFactor( 0.8 );
00403         axes->GetProperty()->SetColor( 1.0, 1.0, 1.0 );
00404 
00405         renderer->ResetCamera();
00406 
00407         renderWindow->Render();
00408 
00409         return;
00410 }
00411 
00412 void
00413 DefOrgViewer
00414 ::LoadMeta()
00415 {
00416         char* fcResult = fl_file_chooser("Pick a mesh file to load", "*.{meta,BYU}", 0, 0);
00417         if( fcResult == NULL){ return; };
00418         std::string choiceStr = fcResult;
00419         std::string inputTopologyFileName;
00420 
00421         std::string prefix = choiceStr.substr( 0, choiceStr.length()-4 );
00422         std::string suffix = choiceStr.substr( choiceStr.length()-4, 4 );
00423         if( suffix == ".BYU" || suffix == ".byu" ) // TODO: use toupper() to simplify comparison
00424         {
00425                 inputTopologyFileName = prefix+".meta";
00426                 int converted = BYUToMeta( choiceStr, inputTopologyFileName );
00427                 if( converted < 0 )
00428                 {
00429                         std::cerr << "Error attempting to convert BYU file to meta format. Do you have write permissions in the directory containing "
00430                                 << choiceStr << "?" << std::endl;
00431                         return;
00432                 }
00433         }
00434         else if( suffix == "META" || suffix == "meta" )
00435         {
00436                 inputTopologyFileName = choiceStr;
00437         }
00438         else
00439         {
00440                 std::cerr << "Error loading mesh. Currently only .meta and .BYU files are supported." << std::endl;
00441         }
00442         
00443         geomLayerPointer->readTopologyFromFile( inputTopologyFileName );
00444         std::cout << "Topology read from '" << inputTopologyFileName << "'..." << std::endl;
00445 
00446         vtkUnstructuredGrid* vtkGrid = MeshToUnstructuredGrid( geomLayerPointer->theMesh );
00447 
00448         meshMapper->SetInput( vtkGrid );
00449         vtkActor* meshActor = vtkActor::New();
00450         meshActor->SetMapper( meshMapper );
00451 
00452         // TEMP: SET THE RGB VALUE OF THE MESH SURFACE HERE:
00453         meshActor->GetProperty()->SetColor( 0.3, 1.0, 0.4 ); // e.g. green
00454 
00455         renderer->AddActor( meshActor );
00456 
00457         renderer->ResetCamera();
00458         renderer->Render();
00459 
00460         return;
00461 }
00462 
00463 void
00464 DefOrgViewer
00465 ::ToggleVolumeRendering()
00466 {
00467         isVolumeRenderingOn = !isVolumeRenderingOn;
00468         (isVolumeRenderingOn) ? volume->VisibilityOn() : volume->VisibilityOff();
00469 }
00470 
00471 //typedef DefOrgViewer::MeshType::Pointer MeshTypePointer;
00472 vtkUnstructuredGrid* 
00473 DefOrgViewer
00474 ::MeshToUnstructuredGrid( MeshTypePointer mesh )
00475 {
00476         // Get the number of points in the mesh
00477         int numPoints = mesh->GetNumberOfPoints();
00478         if(numPoints == 0)
00479         {
00480                 mesh->Print(std::cerr);
00481                 std::cerr << "no points in Grid " << std::endl;
00482                 exit(-1);
00483         }
00484         // Create a vtkUnstructuredGrid
00485         vtkUnstructuredGrid* vgrid = vtkUnstructuredGrid::New();
00486 
00487         // Create the vtkPoints object and set the number of points
00488         vtkPoints* vpoints = vtkPoints::New();
00489         vpoints->SetNumberOfPoints(numPoints);
00490         // iterate over all the points in the itk mesh filling in
00491         // the vtkPoints object as we go
00492         MeshType::PointsContainer::Pointer points = mesh->GetPoints();
00493         for(MeshType::PointsContainer::Iterator i = points->Begin();
00494                 i != points->End(); ++i)
00495         {
00496                 // Get the point index from the point container iterator
00497                 int idx = i->Index();
00498                 // Set the vtk point at the index with the the coord array from itk
00499                 // itk returns a const pointer, but vtk is not const correct, so
00500                 // we have to use a const cast to get rid of the const
00501                 vpoints->SetPoint(idx, const_cast<DataType*>(i->Value().GetDataPointer()));
00502         }
00503         // Set the points on the vtk grid
00504         vgrid->SetPoints(vpoints);
00505 
00506         // Now create the cells using the MulitVisitor
00507         // 1. Create a MultiVisitor
00508         MeshType::CellType::MultiVisitor::Pointer mv =
00509                 MeshType::CellType::MultiVisitor::New();
00510         // 2. Create a triangle and quadrilateral visitor
00511         TriangleVisitor::Pointer tv = TriangleVisitor::New();
00512         QuadrilateralVisitor::Pointer qv =  QuadrilateralVisitor::New();
00513         // 3. Set up the visitors
00514         int vtkCellCount = 0; // running counter for current cell being inserted into vtk
00515         int numCells = mesh->GetNumberOfCells();
00516         int *types = new int[numCells]; // type array for vtk 
00517         // create vtk cells and estimate the size
00518         vtkCellArray* cells = vtkCellArray::New();
00519         cells->EstimateSize(numCells, 4);
00520         // Set the TypeArray CellCount and CellArray for both visitors
00521         tv->SetTypeArray(types);
00522         tv->SetCellCounter(&vtkCellCount);
00523         tv->SetCellArray(cells);
00524         qv->SetTypeArray(types);
00525         qv->SetCellCounter(&vtkCellCount);
00526         qv->SetCellArray(cells);
00527         // add the visitors to the multivisitor
00528         mv->AddVisitor(tv);
00529         mv->AddVisitor(qv);
00530         // Now ask the mesh to accept the multivisitor which
00531         // will Call Visit for each cell in the mesh that matches the
00532         // cell types of the visitors added to the MultiVisitor
00533         mesh->Accept(mv);
00534 
00535         // Now set the cells on the vtk grid with the type array and cell array
00536         vgrid->SetCells(types, cells);
00537 
00538         // Clean up vtk objects (no vtkSmartPointer ... )
00539         cells->Delete();
00540         vpoints->Delete();
00541         // return the vtkUnstructuredGrid
00542         return vgrid;
00543 }
00544 void
00545 DefOrgViewer::TogglePlayPause()
00546 {
00547         //Call the base class
00548         DefOrgViewerGUI::TogglePlayPause();
00549 
00550         //if the Organism has not been setup, then set it up.
00551         if(orgNotSet)
00552         {
00553                 orgNotSet = false;
00554                 this->SetupOrganism();
00555         }
00556 }
00557 
00558 void
00559 DefOrgViewer::SetupOrganism()
00560 {
00561         //TODO:: make this robust (i.e. flag errors if image not set, geom not set etc).
00562         
00563         // Instantiate the organism:
00564         testOrg = OrganismType::New();
00565         std::cout << "Organism created..." << std::endl;
00566         scheduleFileName =              "data\\testSchedule3d.txt"; // TODO: eliminate hardcoded values here
00567 
00568         //Setup the sensor
00569         GradientSensorType::sensorIn input;
00570                 
00571         input.sigma = 1.0;
00572         this->imageReader->Update();
00573         input.imageIn = this->imageReader->GetOutput();
00574         gradientSensor.run((void *)&input);
00575         std::cout << "Gradient sensor setup complete..." << std::endl;
00576         GradientSensorType::sensorOut * output = (GradientSensorType::sensorOut *) gradientSensor.getOuput();
00577 
00578 
00579         //Instantiate geomtery and physics layers
00580         eulerPhysLayerPointer = new EulerPhysicsType(0,0,10);
00581                         
00582         //physLayer.setInput(reader->GetOutput());
00583         eulerPhysLayerPointer->setExternalForces((void *) &(output->imageOut));
00584         eulerPhysLayerPointer->setGeometry(geomLayerPointer);
00585 
00586         testOrg->setPhysicsLayer(eulerPhysLayerPointer);
00587         testOrg->setGeometricLayer(geomLayerPointer);
00588         std::cout << "Physics layer added..." << std::endl;
00589 
00590         //TEST BEHAVIOR
00591         //TODO figure out how to make sure it gets deleted.
00592         //TODO should we attach things by value instead by ref?
00593         cognitiveLayerPointer = new CognitiveType(5);
00594         beh1 = new Beh_TranslateAllType();
00595         def1 = new Def_TranslateAllType();
00596         cognitiveLayerPointer->setSchedule(scheduleFileName);
00597         //Beh_TranslateAll<float, 3> beh1;
00598         //Def_Translation<float, 3> def1;                                                               
00599         this->testOrg->setCognitiveLayer(cognitiveLayerPointer);
00600         this->testOrg->addBehaviour(beh1);
00601         this->testOrg->addDeformation(def1);
00602 
00603         //Pass the output of the reader to the filter, then to the writer.
00604         testOrg->SetInput(imageReader->GetOutput());
00605 }
00606 void
00607 DefOrgViewer
00608 ::UpdateOrganism()
00609 {
00610         //Cause the organism to simulate!
00611         //testOrg->Update();
00612         testOrg->run();
00613         //geomLayerPointer->writeObjectToFile("C:\\test.meta");
00614         //Update the mesh
00615         vtkUnstructuredGrid* vtkGrid = MeshToUnstructuredGrid( geomLayerPointer->theMesh );
00616 
00617         meshMapper->SetInput( vtkGrid );
00618         renderer->Render();
00619 }
00620 
00621 void 
00622 DefOrgViewer
00623 ::ConnectPipelines( itkImageExportType::Pointer exporter, 
00624                                    vtkImageImportType* importer)
00625 {
00626         importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());
00627         importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());
00628         importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());
00629         //  importer->SetSpacingCallback(exporter->GetSpacingCallback());
00630         //  importer->SetOriginCallback(exporter->GetOriginCallback());
00631         importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());
00632         importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());
00633         importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());
00634         importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());
00635         importer->SetDataExtentCallback(exporter->GetDataExtentCallback());
00636         importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());
00637         importer->SetCallbackUserData(exporter->GetCallbackUserData());
00638 }

Generated on Wed Jul 19 13:05:15 2006 for IDO by  doxygen 1.4.7