[vtkusers] How to add scalars to PointData?

David Doria daviddoria+vtk at gmail.com
Sun Jan 10 16:48:46 EST 2010


On Sun, Jan 10, 2010 at 4:31 PM,  <lynx.abraxas at freenet.de> wrote:
> On 10/01/10 13:44:40, lynx.abraxas at freenet.de wrote:
>> Hello!
>>
>>
>> I have unstructured points (on a sphere). Each point has its own weight.
>> I   want   to  use  GaussianSplatter  but  with  a  ScaleFactor  (weight)  set
>> individually  for  each  point.  Sadly  the  wiki   example   does   not   use
>> scalarwarping.
>> How  do  I  get  a  scalar assigned to each point that then weights the splat?
>> SetScaleFactor weights all point same (if I'm not mistaken). I couldn't find a
>> setScalar for vtkPoints either.
>
> I had the idea of using polydata->GetPointData()->SetScalars(weights) (see below) but I get:
>
> error: invalid use of incomplete type 'struct vtkPointData'
> error: forward declaration of 'struct vtkPointData'
>
> How would I have to assigne the scalar array to the Points in the PolyData?
>
> Thanks,
> Lynx
>
>
> vtkPolyData* ReadPoints(char* fn){
> //    std::string Filename = fn;
> //    ifstream fin(Filename.c_str());
>    ifstream fin(fn);
>
>    std::string line;
>    vtkPoints* Points = vtkPoints::New();
>    vtkFloatArray* weights = vtkFloatArray::New();
>    weights->SetNumberOfComponents(1);
>    weights->SetName ("weight");
>
>    while(getline(fin, line))
>        {
>        if (line[0] == '#'){
>            std::cerr << "Skipping line: " << line << std::endl;
>            continue;
>            }
>        unsigned int i;
>        float x,y,z,w;
>        std::stringstream linestream;
>        linestream << line;
>        linestream >> i >> x >> y >> z >> w;
>        printf("Adding point (%d): [%f;%f;%f] with weight: %f\n", i, x, y, z, w);
>        Points->InsertNextPoint(x, y, z);
>        //Points->SetScalar(w);
>        weights->InsertNextValue(w); //InsertNextTuple1
>        }
>
>    vtkPolyData* polydata = vtkPolyData::New();
>    polydata->SetPoints(Points);
>    polydata->GetPointData()->SetScalars(weights);
>    //polydata->GetPointData()->AddArray(weights);
>    fin.close();
>
>    return polydata;
>    }
>

Lynx,
All this means:
error: invalid use of incomplete type 'struct vtkPointData'
error: forward declaration of 'struct vtkPointData'

is that you need to #include <vtkPointData.h>

:)

 polydata->GetPointData();

returns a vtkPointData, so when you call:

 polydata->GetPointData()->SetScalars(weights);

the compiler needs to know what a vtkPointData is.

Thanks,

David



More information about the vtkusers mailing list