[vtkusers] Point array with 3 components, only has 0 tuples but there are 4 points
Bill Lorensen
bill.lorensen at gmail.com
Sun Dec 30 00:26:21 EST 2007
Tracy,
You should be using:
colorArray->InsertTuple3(0,0,0,0);
colorArray->InsertTuple3(1,0,0,0);
colorArray->InsertTuple3(2,0,0,0);
colorArray->InsertTuple3(3,0,0,0);
InsertNextTuple3 will add to the already allocated colorArray.
This does not explain the error message you get however.
Bill
On Dec 28, 2007 8:28 PM, Tracy Hu <tracy.hu at yahoo.com> wrote:
> Hello,
>
> I'm trying to write a image filter, but I got this error:
>
> ERROR: In \vwdev\PC\Libraries\vtk44\src\Common\vtkDataSet.cxx, line 376
> vtkImageData (02476728): Point array color array with 3 components, only
> has 0
> tuples but there are 4 points
>
> do you have any idea?
>
> Below are my code:
>
> //------------main.cpp-------------------
> #include "vtkRenderer.h"
> #include "vtkRenderWindow.h"
> #include "vtkRenderWindowInteractor.h"
> #include "vtkInteractorStyleTrackballCamera.h"
> #include "vtkPoints.h"
> #include "vtkDataSetMapper.h"
> #include "vtkImageData.h"
> #include "vtkPointData.h"
> #include "CImageMerger.h"
>
> int main( int argc, char *argv[] )
> {
> CImageMerger *reader = CImageMerger::New();
> reader->Update();
> cout <<"main: # of tuples in color array: " <<
> reader->GetOutput()->GetPointData()->GetArray(0)->GetNumberOfTuples()
> <<endl;
>
> vtkDataSetMapper *mapper = vtkDataSetMapper::New();
> mapper->SetInput(reader->GetOutput());
>
> vtkActor *actor = vtkActor::New();
> actor->SetMapper(mapper);
>
> vtkRenderer* ren = vtkRenderer::New();
> ren->AddActor(actor);
> ren->SetBackground(1, 1, 1);
>
> vtkRenderWindow* renWin = vtkRenderWindow::New();
> renWin->AddRenderer(ren);
>
> vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
> iren->SetRenderWindow(renWin);
> vtkInteractorStyleTrackballCamera *style =
> vtkInteractorStyleTrackballCamera::New();
> iren->SetInteractorStyle(style);
> renWin->SetSize(600,600);
> renWin->Render();
> iren->Start();
>
> style->Delete();
> iren->Delete();
> ren->Delete();
> renWin->Delete();
> actor->Delete();
> mapper->Delete();
> reader->Delete();
> return 0;
>
> }
>
>
> //-------------CImageMerger.cpp--------------
> #include "vtkFloatArray.h"
> #include "vtkPointData.h"
> #include "vtkObjectFactory.h"
> #include <vector>
> #include "vtkUnsignedCharArray.h"
> #include "vtkImageData.h"
> #include "CImageMerger.h"
>
> vtkCxxRevisionMacro(CImageMerger, "$Revision: 1.30 $");
> vtkStandardNewMacro(CImageMerger);
>
> CImageMerger::CImageMerger():vtkImageSource()
> {}
> CImageMerger::~CImageMerger()
> {}
>
> void CImageMerger::ExecuteData(vtkDataObject*)
> {
> this->GetOutput()->SetDimensions(2, 2, 1);
> this->GetOutput()->SetSpacing(1.0,1.0,1.0);
> this->GetOutput()->SetOrigin(0.0,0.0,0.0);
> this->GetOutput()->SetScalarType(VTK_UNSIGNED_CHAR);
> vtkUnsignedCharArray *colorArray = vtkUnsignedCharArray::New();
> colorArray->SetNumberOfComponents(3);
> colorArray->SetNumberOfTuples(4);
> colorArray->InsertNextTuple3(0,0,0);
> colorArray->InsertNextTuple3(0,0,0);
> colorArray->InsertNextTuple3(0,0,0);
> colorArray->InsertNextTuple3(0,0,0);
> colorArray->SetName("color array");
> this->GetOutput()->GetPointData()->SetScalars(colorArray);
> }
>
> void CImageMerger::ExecuteInformation()
> {
> }
>
> void CImageMerger::PrintSelf(ostream& os, vtkIndent indent)
> {
> }
>
> //--------CImageMerger.h-------------------
> #include "vtkImageSource.h"
>
> class CImageMerger : public vtkImageSource
> {
> public:
> vtkTypeRevisionMacro(CImageMerger, vtkImageSource);
> void PrintSelf(ostream& os, vtkIndent indent);
> static CImageMerger *New();
>
> CImageMerger();
> ~CImageMerger();
>
> protected:
> void ExecuteInformation();
> void ExecuteData(vtkDataObject*);
>
> private:
> CImageMerger(const CImageMerger&); // Not implemented.
> void operator=(const CImageMerger&); // Not implemented.
>
>
> };
>
>
> thanks
>
> tracy
>
>
>
> ------------------------------
> Never miss a thing. Make Yahoo your homepage.<http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs>
>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20071230/30556e46/attachment.htm>
More information about the vtkusers
mailing list