[vtkusers] Update scalars in the Unstructuredgrid

Naim naim at electromagneticworks.com
Fri Sep 22 17:43:49 EDT 2006


Hi vtkUsers,

 

I sent an email yesterday to explain my problem; I think that I don't
explain it clearly. So my question is:

Why when I change the scalars in my unstructured grid, the output results
change with a wrong data; my plot is not correct.

 

I change the scalars like this:

 

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

 

double* pPlotData = m_plotDataArray->GetAt(step); // new scalars data, I
checked a data

 

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

{             

if(pPlotData)        

       {             

              aNodeValue = pPlotData[i];               

              pScalars->SetValue(i, aNodeValue);                      

       }             

}             

pScalars->Modified();

ren->Render();

 

This is my pipeline:    

 

m_pUnstructuredGrid = vtkUnstructuredGrid::New();

 

// We now assign the pieces to the vtkPolyData.

vtkPolyData* theModel = vtkPolyData::New();

       theModel->SetPolys(m_pPolys); // m_pPolys is vtkCellArray

 

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); // pPoints is vtkPoints

 

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

 

vtkGeometryFilter* extract = vtkGeometryFilter::New(); 

       extract->SetInput(m_pUnstructuredGrid);

 

vtkPolyDataNormals* normals = vtkPolyDataNormals::New(); 

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

normals->SetFeatureAngle(60.0);

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

 

vtkStripper* stripper = vtkStripper::New(); 

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

 

vtkDataSetMapper* contourMapper = vtkDataSetMapper::New();

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

contourMapper->SetScalarRange(m_GlobalMinValue,m_GlobalMaxValue);

       contourMapper->SetLookupTable(m_pColours);

       contourMapper->ScalarVisibilityOn();

       contourMapper->SetColorModeToMapScalars();

       contourMapper->UseLookupTableScalarRangeOn();

       contourMapper->InterpolateScalarsBeforeMappingOn();

 

vtkActor* pContinuousFringeActor = vtkActor::New();

       pContinuousFringeActor->SetMapper(contourMapper);

       pContinuousFringeActor->VisibilityOn();

 

       // add to rendering

m_prenderer->AddViewProp(pContinuousFringeActor);

 

Thank you for your help.

 

Naim Himrane

Electromagneticworks inc.

 

  _____  

From: vtkusers-bounces+naim=electromagneticworks.com at vtk.org
[mailto:vtkusers-bounces+naim=electromagneticworks.com at vtk.org] On Behalf Of
Naim
Sent: September 21, 2006 4:37 PM
To: 'vtkusers'
Subject: [vtkusers] Update vtkUnstructuredgrid

 

 

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/20060922/4abd4c08/attachment.htm>


More information about the vtkusers mailing list