[vtkusers] Symmetry questions

Banksie banks at wai.com
Mon Feb 8 18:24:34 EST 2010


Hi David,

You'll have to forgive me if this doesn't work straight out the box, it's
grabbed from a few routines but hope if does everything. If xFlipped is true
and yFlipped is false, the code works. If both xFlipped and yFlipped are
true the code crashes.

Regards
Robbie

#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyData.h>
#include <vtkTransform.h>
#include <vtkTransformPolyDataFilter.h>
#include <vtkAppendPolyData.h>
#include <vtkCylinderSource.h>
 
int main (int argc, char *argv[])
{
  vtkSmartPointer<vtkCylinderSource> source =
vtkSmartPointer<vtkCylinderSource>::New();
  source->SetCenter(1,1,1);

   // Add a new vtkPolyDataMapper to deal with the new symmetrical data
   vtkSmartPointer<vtkPolyDataMapper> pMapperSymm =
vtkSmartPointer<vtkPolyDataMapper>::New();

  // Actor in scene
  vtkSmartPointer<vtkActor>pActor = vtkSmartPointer<vtkActor>::New();

   vtkSmartPointer<vtkRenderer> pRenderer =
vtkSmartPointer<vtkRenderer>::New();

   vtkSmartPointer<vtkRenderWindow> pRenderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
   pRenderWindow->AddRenderer(pRenderer);

  // Add Actor to renderer
  pRenderer->SetBackground(1,1,1); // Background color white

       // Determine which axes are flipped
       bool xFlipped=true;
       bool yFlipped=true;

       // Add a vtkTranform to apply symmetry to the dataset
       vtkSmartPointer<vtkTransform> pTranslationX =
vtkSmartPointer<vtkTransform>::New();
       vtkSmartPointer<vtkTransform> pTranslationY =
vtkSmartPointer<vtkTransform>::New();

       // Add a new vtkPolyData to deal with the new symmetrical data
       vtkSmartPointer<vtkPolyData> pNewData =
vtkSmartPointer<vtkPolyData>::New();
       // Add a new vtkAppendData to deal with the new symmetrical data
       vtkSmartPointer<vtkAppendPolyData> pAppendData =
vtkSmartPointer<vtkAppendPolyData>::New();

       // Create translation to data for given symmetry
       pTranslationX->Translate(1.0, 0.0, 0.0);
       pTranslationY->Translate(0.0, 1.0, 0.0);

       // Add the source data  
      pAppendData->AddInput(source->GetOutput());
      pAppendData->AddInput(source->GetOutput());
      vtkSmartPointer<vtkPolyData> pNewSourceData = source->GetOutput();

       if(xFlipped){
               // Apply translation filter to data for given symmetry
               vtkSmartPointer<vtkTransformPolyDataFilter> pTransformFilter1
=
                         
vtkSmartPointer<vtkTransformPolyDataFilter>::New();
               pTransformFilter1->SetInput(pNewSourceData);
               pTransformFilter1->SetTransform(pTranslationX);
               pTransformFilter1->Update();

               // Create a vtkPolyData set and add it to the
vtkAppendPolyData for the symmetrical data
               vtkSmartPointer<vtkPolyData> pData1 =
pTransformFilter1->GetOutput();
               pAppendData->AddInput(pData1);
       }
       if(yFlipped){
               // Apply translation filter to data for given symmetry
               vtkSmartPointer<vtkPolyData> pTempData =
pAppendData->GetOutput();
               vtkSmartPointer<vtkTransformPolyDataFilter> pTransformFilter2
=
                      vtkSmartPointer<vtkTransformPolyDataFilter>::New();
               pTransformFilter2->SetInput(pTempData);
               pTransformFilter2->SetTransform(pTranslationY);
               pTransformFilter2->Update();

               // Create a vtkPolyData set and add it to the
vtkAppendPolyData for the symmetrical data
               vtkPolyData * pData1 = pTransformFilter2->GetOutput();
               pAppendData->AddInput(pData1);
       }

      // Finally copy all the appended data to a new vtkPolyData set
       pNewSourceData = pAppendData->GetOutput();

       // Remap the data for display
       pMapperSymm->SetInput(pNewSourceData);

       // Add Mapper to Actor
       pActor->SetMapper(pMapperSymm);

        // Add Actor to renderer
        pRenderer->AddActor(pActor);
        // Reset camera
        pRenderer->ResetCamera();
        pRenderer->GetRenderWindow()->Render();
}


David Doria-2 wrote:
> 
> 
> A quick thing, you should use
> vtkSmartPointer<className> variableName =
> vtkSmartPointer<className>::New();
> instead of
> className* variableName = className::New();
> 
> Then you do not have to have the big block of Deletes()'s at the end of
> the
> code :)
> 
> Can you make an post the simplest compilable example that demonstrates the
> problem? It's much easier to debug if I can step through myself.
> 
> Thanks,
> 
> David
> 
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
> 
> 

-- 
View this message in context: http://old.nabble.com/Symmetry-questions-tp27474607p27508027.html
Sent from the VTK - Users mailing list archive at Nabble.com.




More information about the vtkusers mailing list