[vtkusers] Point array with 3 components, only has 0 tuples but there are 4 points

Tracy Hu tracy.hu at yahoo.com
Fri Dec 28 20:28:37 EST 2007


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20071228/b0ac7221/attachment.htm>


More information about the vtkusers mailing list