[vtkusers] Symmetry questions
David Doria
daviddoria+vtk at gmail.com
Mon Feb 8 17:57:55 EST 2010
On Mon, Feb 8, 2010 at 5:17 PM, Banksie <banks at wai.com> wrote:
>
> Hi again,
>
> I'm a lot closer than I was, but I'm getting something a bit strange. When
> I
> apply symmetry to one axis, everything works fine, but when I move to
> having
> two axes with symmetry, I get a Seg Fault when it comes to the
>
> pRenderer->GetRenderWindow->Render();
>
> Command at the end of the code. I've attached the code below. Am I doing
> something silly?
>
> Thanks again
> Robbie
>
> void SnapshotView::slotSymmetry(const bool & flip, const int & axis)
> {
> // Determine which axes are flipped
> if(axis==xAxis) xFlipped=flip;
> if(axis==yAxis) yFlipped=flip;
> if(axis==zAxis) zFlipped=flip;
>
> // Add a vtkTranform to apply symmetry to the dataset
> vtkTransform * pTranslationX = vtkTransform::New();
> vtkTransform * pTranslationY = vtkTransform::New();
> vtkTransform * pTranslationZ = vtkTransform::New();
>
> // Add a new vtkPolyDataMapper to deal with the new symmetrical data
> vtkPolyDataMapper * pMapperSymm = vtkPolyDataMapper::New();
> // Add a new vtkPolyData to deal with the new symmetrical data
> vtkPolyData * pNewData = vtkPolyData::New();
> // Add a new vtkAppendData to deal with the new symmetrical data
> vtkAppendPolyData * pAppendData = 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);
> pTranslationZ->Translate(0.0, 0.0, 1.0);
>
> // Add the source data pAppendData->AddInput(source->GetOutput());
> to our
> new vtkAppendData
> pAppendData->AddInput(source->GetOutput());
> vtkPolyData * pNewSourceData = source->GetOutput();
>
> if(xFlipped){
> // Apply translation filter to data for given symmetry
> vtkTransformPolyDataFilter * pTransformFilter1 =
> vtkTransformPolyDataFilter::New();
> pTransformFilter1->SetInput(pNewSourceData);
> pTransformFilter1->SetTransform(pTranslationX);
> pTransformFilter1->Update();
>
> // Create a vtkPolyData set and add it to the
> vtkAppendPolyData for the
> symmetrical data
> vtkPolyData * pData1 = pTransformFilter1->GetOutput();
> pAppendData->AddInput(pData1);
> }
>
> if(yFlipped){
> // Apply translation filter to data for given symmetry
> vtkPolyData * pTempData = pAppendData->GetOutput();
> vtkTransformPolyDataFilter * pTransformFilter2 =
> 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);
> }
>
>
> if(zFlipped){
> // Apply translation filter to data for given symmetry
> vtkPolyData * pTempData2 = pAppendData->GetOutput();
> vtkTransformPolyDataFilter * pTransformFilter3 =
> vtkTransformPolyDataFilter::New();
> pTransformFilter3->SetInput(pTempData2);
> pTransformFilter3->SetTransform(pTranslationZ);
> pTransformFilter3->Update();
>
> // Create a vtkPolyData set and add it to the
> vtkAppendPolyData for the
> symmetrical data
> vtkPolyData * pData1 = pTransformFilter3->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();
>
> pTranslationX->Delete();
> pTranslationY->Delete();
> pTranslationZ->Delete();
> pAppendData->Delete();
> pNewData->Delete();
> pNewSourceData->Delete();
> }
>
>
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100208/1544464a/attachment.htm>
More information about the vtkusers
mailing list