[vtkusers] render color vectos overlaping original image, the given pictur is unwanted result
甘建红
76565122 at qq.com
Thu Dec 5 02:35:28 EST 2013
Hi all,
I have 2 scalar images u and v, and compose a new image with vector pixel. My goal is render the composed vectors overlap original imge, but all vectors image show at the window center and shrinked, and the original image appear left-down corner of the same window as show in the picture. the problem has impede me. any help will be appreciated and thanks for all in advance.
====I holpe the colorful vectors overlape on the image located at left-buttom corner====
The related program is given as following.
typedef itk::Vector<float,3> VectorPixelType; ////////////////////////////////////
typedef itk::Image<VectorPixelType,2> VectorImage2DType;
// compose a image with vector pixel with two scalar images u and v
typedef itk::ComposeImageFilter<Image2DfType,VectorImage2DType> ImageToVectorImageFilterType;
ImageToVectorImageFilterType::Pointer imageToVectorImageFilter=ImageToVectorImageFilterType::New();
imageToVectorImageFilter->SetInput(0,u);
imageToVectorImageFilter->SetInput(1,v);
imageToVectorImageFilter->SetInput(2,v);
imageToVectorImageFilter->Update();
// convert the image with vector pixel to vtk image
ExportFilterType::Pointer itkExporter=ExportFilterType::New();
itkExporter->SetInput(imageToVectorImageFilter->GetOutput());
itkExporter->Update();
ConnectPipelines(itkExporter,vtkImporter);
vtkImporter->Update();
// compute vector magnitude and add it to vtkImporter by AddArray function.
vtkSmartPointer<vtkImageMagnitude> magnitudeFilter=vtkSmartPointer<vtkImageMagnitude>::New();
magnitudeFilter->SetInputConnection(vtkImporter->GetOutput()->GetProducerPort());
magnitudeFilter->Update();
magnitudeFilter->GetOutput()->GetPointData()->GetScalars()->SetName("ColorValue");
magnitudeFilter ->Update();
vtkImporter->GetOutput()->GetPointData()->AddArray(magnitudeFilter->GetOutput()->GetPointData()->GetScalars());
vtkSmartPointer<vtkMaskPoints> maskP=vtkSmartPointer<vtkMaskPoints>::New();
maskP->SetOnRatio(250);
maskP->RandomModeOff();
maskP->SetInputConnection(vtkImporter->GetOutputPort());
maskP->Update(); /////////////
maskP->GetOutput()->GetPointData()->SetActiveVectors(vectorname.c_str());
vtkSmartPointer<vtkGlyphSource2D> arrowSource =vtkSmartPointer<vtkGlyphSource2D>::New();
arrowSource->SetGlyphTypeToArrow();
arrowSource->SetScale2(1);
arrowSource->FilledOff();
arrowSource->CrossOff();
arrowSource->Update();
vtkSmartPointer<vtkGlyph2D> glyphFilter = vtkSmartPointer<vtkGlyph2D>::New();
glyphFilter->SetSourceConnection(arrowSource->GetOutputPort());
glyphFilter->OrientOn();
glyphFilter->SetScaleModeToScaleByScalar(); // 2013.11.30 22:50
glyphFilter->SetColorModeToColorByScalar();
glyphFilter->SetScaleFactor(10);
glyphFilter->SetInputConnection(maskP->GetOutputPort());
glyphFilter->Update();
vtkSmartPointer<vtkImageSliceMapper> imageMapper = vtkSmartPointer<vtkImageSliceMapper>::New();
imageMapper->SetInputConnection(vtkImporter->GetOutput()->GetProducerPort());
vtkSmartPointer<vtkLookupTable> Lut=vtkSmartPointer<vtkLookupTable>::New();
Lut->SetTableRange(-20,20);
Lut->SetHueRange(0,1);
Lut->SetSaturationRange(1,1);
Lut->SetValueRange(1,1); //////////
Lut->SetAlpha(1);
Lut->SetValueRange(-20,60);
Lut->SetNumberOfTableValues(25600);
Lut->SetRange(-20,60);
Lut->Build();
vtkSmartPointer<vtkImageSlice> imageSlice = vtkSmartPointer<vtkImageSlice>::New();
imageSlice->SetMapper(imageMapper);
vtkSmartPointer<vtkPolyDataMapper> vectorMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
vectorMapper->SetInputConnection(glyphFilter->GetOutputPort());
vectorMapper->SetScalarRange(-20,20);
vectorMapper->ScalarVisibilityOn();
vectorMapper->SetLookupTable(Lut);
vectorMapper->SetScalarModeToUsePointFieldData();
vectorMapper->ColorByArrayComponent("ColorValue",3);
vectorMapper->SetColorModeToMapScalars();
vectorMapper->SelectColorArray("ColorValue");
vectorMapper->UseLookupTableScalarRangeOn();
vectorMapper->ScalarVisibilityOn();
vtkSmartPointer<vtkActor> vectorActor = vtkSmartPointer<vtkActor>::New();
vectorActor->SetMapper(vectorMapper);
this->GetRenderer()->AddActor(vectorActor);
this->GetRenderer()->ResetCamera();
GetInteractor()->Render();
this->GetRenderer()->Render();
this->Invalidate(false);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20131205/8b0fbd18/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/jpeg
Size: 45891 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20131205/8b0fbd18/attachment-0001.jpeg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ImageAndVectorSep.JPG
Type: application/octet-stream
Size: 45891 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20131205/8b0fbd18/attachment-0001.obj>
More information about the vtkusers
mailing list