[prev in list] [next in list] [prev in thread] [next in thread]
List: vtk-developers
Subject: [vtk-developers] =?utf-8?q?writing_own_filter_to_delete_a_cell?=
From: "Rakesh Patil" <rakeshthp () in ! com>
Date: 2010-04-14 8:55:03
Message-ID: 1271235256.21ce689121e39821d07d04faab328370 () mail ! in ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Hello users,Here are the two files which i have written. The filters to remove \
points and cells from an unstructured grid. It accepts an unstructured grid as an \
input and returns new unstructured grid as an output..When i check the number of \
points and number of cells of the output grid, it shows correctly.. But when i render \
the output grid, it gives error..Can anyone find out the mistake?? should ids be in \
sequence while rendering..?? The logic is based on the example \
belowhttp://www.vtk.org/Wiki/VTK/Examples/DeletePointHelp, guidance from any of the \
seniors wil be appreciatedThanksRegardsRakesh Patil
[Attachment #5 (text/html)]
Hello users,<br><br>Here are the two files which i have written. The filters to \
remove points and cells from an unstructured grid. It accepts an unstructured grid as \
an input and returns new unstructured grid as an output..<br><br>When i check the \
number of points and number of cells of the output grid, it shows correctly.. But \
when i render the output grid, it gives error..<br><br>Can anyone find out the \
mistake?? should ids be in sequence while rendering..?? The logic is based on the \
example below<br><br><a target=\"_blank\" target="\"_blank\"" \
href="http://www.vtk.org/Wiki/VTK/Examples/DeletePoint">http://www.vtk.org/Wiki/VTK/Examples/DeletePoint</a><br><br>Help, \
guidance from any of the seniors wil be \
appreciated<br><br>Thanks<br><br>Regards<vtkusers@vtk.org><br>Rakesh \
Patil<br></vtkusers@vtk.org>
----1629165ae574cbdac1227c370dfbb23a6735--
["MyRemoveFilter.h" (text/x-c)]
#ifndef _MYREMOVEFILTER_
#define _MYREMOVEFILTER_
#include <deque>
#include <vtkUnstructuredGrid.h>
#include <vtkPolyData.h>
#include <vtkPoints.h>
#include <vtkSmartPointer.h>
class MyRemoveFilter
{
vtkUnstructuredGrid *_inGrid, *_outGrid;
vtkSmartPointer<vtkPoints> _newPoints;
std::deque<vtkIdType> removePointIdList, removeCellIdList;
public:
static MyRemoveFilter *New();
void Delete();
vtkUnstructuredGrid *getOutput() { return _outGrid; }
void setInput(vtkUnstructuredGrid *grid) { _inGrid->ShallowCopy(grid); }
void removeCell(vtkIdType _cellId);
void removePoint(vtkIdType _pointId);
void Update();
protected:
MyRemoveFilter();
~MyRemoveFilter();
};
#endif
["MyRemoveFilter.cpp" (text/x-c)]
#include <vtkCellArray.h>
#include <vtkCellData.h>
#include <vtkGenericCell.h>
#include "MyRemoveFilter.h"
MyRemoveFilter::MyRemoveFilter()
{
_inGrid = vtkUnstructuredGrid::New();
_outGrid = vtkUnstructuredGrid::New();
_newPoints = vtkSmartPointer<vtkPoints>::New();
}
MyRemoveFilter::~MyRemoveFilter()
{
_inGrid->Delete();
_outGrid->Delete();
}
MyRemoveFilter* MyRemoveFilter::New()
{
return new MyRemoveFilter();
}
void Delete()
{
this->~MyRemoveFilter();
}
void MyRemoveFilter::removeCell(vtkIdType _cellId)
{
vtkSmartPointer<vtkIdList> ptIds = vtkSmartPointer<vtkIdList>::New();
_inGrid->GetCellPoints(_cellId, ptIds);
int numId = ptIds->GetNumberOfIds();
for(int i = 0; i < numId; i++ )
removePoint(ptIds->GetId(i));
removeCellIdList.push_back(_cellId);
}
void MyRemoveFilter::removePoint(vtkIdType _pointId)
{
removePointIdList.push_back(_pointId);
}
bool MyRemoveFilter::isInRemoveList(vtkIdType _id, std::deque<vtkIdType> _list)
{
// Checks whether the _id is present in _list
std::deque<vtkIdType>::iterator fit = _list.begin();
std::deque<vtkIdType>::iterator eit = _list.end();
while( fit != eit )
{
if( (*fit) == _id )
return true;
fit++;
}
return false;
}
void MyRemoveFilter::Update()
{
vtkIdList *ptId = vtkIdList::New ();
// remove points
int numPts = _inGrid->GetPoints()->GetNumberOfPoints();
for( int i = 0; i < numPts; i++ )
{
if( !isInRemoveList(i, removePointIdList) )
{
double p[3];
_inGrid->GetPoints()->GetPoint(i, p);
_newPoints->InsertNextPoint(p);
}
}
_outGrid->SetPoints(_newPoints);
// Now remove cells if any
numPts = _inGrid->GetCells()->GetNumberOfCells();
for ( int i = 0; i < numPts; i++ )
{
vtkSmartPointer<vtkGenericCell> _cell = vtkSmartPointer<vtkGenericCell>::New();
_inGrid->GetCell(i, _cell);
_outGrid->InsertNextCell( _cell->GetCellType(), _cell->GetPointIds() );
}
// TODO: consider the scalars and vectors
}
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtk-developers
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic