[vtkusers] Update vtkUnstructuredgrid

Naim naim at electromagneticworks.com
Thu Sep 21 16:36:35 EDT 2006


 

Hi vtkUsers,

 

I'm trying to animate my unstructuredgrid by modifying the scalars. When I
update the unstructured grid the result shown is not correct.

I'm using vtkAnimationScene and vtkAnimationCue for the animation.

 

I would like know if I'm missing any thing in this code:

 

// the unstructured grid was created like this

 

void CGLModelViewCtrl::CreateModel(void)

{     

m_pUnstructuredGrid = vtkUnstructuredGrid::New();

 

      // We now assign the pieces to the vtkPolyData.

      vtkPolyData* theModel = vtkPolyData::New();

            theModel->SetPolys(m_pPolys);

 

      vtkIdList *pIds = vtkIdList::New();

      for (int i=0; i<theModel->GetNumberOfCells(); ++i) 

            pIds->InsertNextId(i);

 

      for (i=0; i< theModel->GetNumberOfCells(); ++i) 

      {

            theModel->GetCellPoints(i, pIds);

            m_pUnstructuredGrid->InsertNextCell(VTK_TETRA,pIds);

      }

 

      m_pUnstructuredGrid->SetPoints(m_pPoints);

 

      if(m_PlotType == VECTORPLOT)

            m_pUnstructuredGrid->GetPointData()->SetVectors(m_pVectors);

      else

            m_pUnstructuredGrid->GetPointData()->SetScalars(m_pScalars);

 

 

      .................

 

      // convert from unstructuredGrid to PolyData

      vtkGeometryFilter *extract = vtkGeometryFilter::New(); 

            extract->SetInput(m_pUnstructuredGrid);

            extract->GetOutput()->ReleaseDataFlagOn();

 

      vtkPolyDataNormals * normals = vtkPolyDataNormals::New(); // none

                  normals->SetInputConnection(extract->GetOutputPort());

                  normals->SetFeatureAngle(60.0);

                  normals->GetOutput()->ReleaseDataFlagOn();

 

      vtkStripper* stripper = vtkStripper::New(); // none

                  stripper->SetInputConnection(normals->GetOutputPort());

 

      vtkDataSetMapper *contourMapper = vtkDataSetMapper::New();

            contourMapper->SetInputConnection(stripper->GetOutputPort());

 

 

      ...............

 

 

      m_pContinuousFringeActor = vtkActor::New();

            m_pContinuousFringeActor->SetMapper(contourMapper);

 

      // add to rendering

      m_prenderer->AddViewProp(m_pContinuousFringeActor);

}

 

// the animation function:

 

void Tick(vtkAnimationCue::AnimationCueInfo* info, vtkRenderer* ren)

{

      if(!m_pUnstructuredGrid)

      {

            AfxMessageBox(_T(" Cue --> No data to plot"));

            return;

      }

 

      vtkDoubleArray* pScalars =
(vtkDoubleArray*)(m_pUnstructuredGrid->GetPointData()->GetScalars());

 

      double aNodeValue = 0;

 

      int step = (int)(info->AnimationTime) - 1; 

      

      double* pPlotData = m_plotDataArray->GetAt(step);

 

      for(long i = 0; i < m_Size; ++i)

      {

            if(pPlotData)

            {

                  aNodeValue = pPlotData[i];

                  pScalars->SetValue(i, aNodeValue);  

            }

      }

      pScalars->Modified();

      m_pUnstructuredGrid->Modified;

 

      this->Actor->GetMapper()->GetInput()->Modified();

      ren->Render();

    }

 

 

Thanks.

 

Naim Himrane

Electromagneticworks inc.

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060921/3d412775/attachment.htm>


More information about the vtkusers mailing list