[vtkusers] Creating Volume-Rendering compatible data

Randall Hand randall.hand at gmail.com
Fri Feb 25 11:33:18 EST 2005


I'm using the following code to "pad" the data the way I want for rendering:

It takes my Scalar+Vector dataset and adds a field that's a
2-component Scalar (Original Scalar + Vector Magnitude), both scaled
between 0 & 255.  I want to map Opacity to the first component, &
color through a lookup table to the 2nd component.

But when it's done, I still can't hand it off to the RayCast mapper because 
   1) It's not an "ImageData"
   2) It's not "unsigned char's", it's "floats"

How can I get from what I have to something that's RayCastMapper compatible?


*snip*
    vtkDataSetReader *model = vtkDataSetReader::New();
    model->SetFileName(filename);
    model->Update();
    char function[128];
    vtkArrayCalculator *addMag = vtkArrayCalculator::New();
    addMag->SetInput(model->GetOutput());
    addMag->AddVectorArrayName("Velocity", 0);
    model->GetOutput()->GetPointData()->GetArray("Velocity")->GetRange(range,
-1);
    sprintf(function, "mag(Velocity) * %f", 255.0 / (range[1] - range[0]));
    addMag->SetFunction(function);
    addMag->SetResultArrayName("Magnitude");
    addMag->Update();
    printf("**************************************************\n");
    PrintStatistics(addMag);
    PrintStatistics(addMag->GetOutput());/*}}}*/
    
    // Scale Fraction field {{{ 
    vtkArrayCalculator *scaled = vtkArrayCalculator::New();
    scaled->SetInput(addMag->GetOutput());
    scaled->AddScalarArrayName("Fraction", 0);
    scaled->SetFunction("Fraction * 255.0");
    scaled->SetResultArrayName("ScaledFraction");
    scaled->Update();
    printf("**************************************************\n");
    PrintStatistics(scaled);
    PrintStatistics(scaled->GetOutput());/*}}}*/
    
    vtkMergeFields *doubleScalar =
                vtkMergeFields::New();
    doubleScalar->SetInput(scaled->GetOutput());
    doubleScalar->SetOutputField("Combined", vtkMergeFields::POINT_DATA);
    doubleScalar->SetNumberOfComponents(2);
    doubleScalar->Merge(0, "Magnitude", 0);
    doubleScalar->Merge(1, "ScaledFraction", 0);
    doubleScalar->Update();
    PrintStatistics(doubleScalar);
    PrintStatistics(doubleScalar->GetOutput()); 
*snip*
-- 
Randall Hand
http://www.yeraze.com



More information about the vtkusers mailing list