[vtkusers] How to add scalars to PointData?

lynx.abraxas at freenet.de lynx.abraxas at freenet.de
Sun Jan 10 16:31:42 EST 2010


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;
    }
 



More information about the vtkusers mailing list