Please keep the discussion to the mailing list. What is the expected result here?
On Fri, Sep 13, 2013 at 11:06 AM, 庞庆源 <[email protected]> wrote: > Why this example can color the cube? > > > 2013/9/13 庞庆源 <[email protected]> > >> Thank you for your reply.I would like to show you a example and its >> picture: >> >> /*========================================================================= >> >> Program: Visualization Toolkit >> Module: Cube.cxx >> >> Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen >> All rights reserved. >> See Copyright.txt or http://www.kitware.com/Copyright.htm for details. >> >> This software is distributed WITHOUT ANY WARRANTY; without even >> the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR >> PURPOSE. See the above copyright notice for more information. >> >> >> =========================================================================*/ >> // This example shows how to manually create vtkPolyData. >> >> #include "vtkActor.h" >> #include "vtkCamera.h" >> #include "vtkCellArray.h" >> #include "vtkFloatArray.h" >> #include "vtkPointData.h" >> #include "vtkPoints.h" >> #include "vtkPolyData.h" >> #include "vtkPolyDataMapper.h" >> #include "vtkRenderWindow.h" >> #include "vtkRenderWindowInteractor.h" >> #include "vtkRenderer.h" >> >> int main() >> { >> int i; >> static float x[8][3]={{0,0,0}, {1,0,0}, {1,1,0}, {0,1,0}, >> {0,0,1}, {1,0,1}, {1,1,1}, {0,1,1}}; >> static vtkIdType pts[6][4]={{0,1,2,3}, {4,5,6,7}, {0,1,5,4}, >> {1,2,6,5}, {2,3,7,6}, {3,0,4,7}}; >> >> // We'll create the building blocks of polydata including data >> attributes. >> vtkPolyData *cube = vtkPolyData::New(); >> vtkPoints *points = vtkPoints::New(); >> vtkCellArray *polys = vtkCellArray::New(); >> vtkFloatArray *scalars = vtkFloatArray::New(); >> >> // Load the point, cell, and data attributes. >> for (i=0; i<8; i++) points->InsertPoint(i,x[i]); >> for (i=0; i<6; i++) polys->InsertNextCell(4,pts[i]); >> for (i=0; i<8; i++) scalars->InsertTuple1(i,i); >> >> // We now assign the pieces to the vtkPolyData. >> cube->SetPoints(points); >> points->Delete(); >> cube->SetPolys(polys); >> polys->Delete(); >> cube->GetPointData()->SetScalars(scalars); >> scalars->Delete(); >> >> // Now we'll look at it. >> vtkPolyDataMapper *cubeMapper = vtkPolyDataMapper::New(); >> cubeMapper->SetInputData(cube); >> cubeMapper->SetScalarRange(0,7); >> vtkActor *cubeActor = vtkActor::New(); >> cubeActor->SetMapper(cubeMapper); >> >> // The usual rendering stuff. >> vtkCamera *camera = vtkCamera::New(); >> camera->SetPosition(1,1,1); >> camera->SetFocalPoint(0,0,0); >> >> vtkRenderer *renderer = vtkRenderer::New(); >> vtkRenderWindow *renWin = vtkRenderWindow::New(); >> renWin->AddRenderer(renderer); >> >> vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); >> iren->SetRenderWindow(renWin); >> >> renderer->AddActor(cubeActor); >> renderer->SetActiveCamera(camera); >> renderer->ResetCamera(); >> renderer->SetBackground(1,1,1); >> >> renWin->SetSize(300,300); >> >> // interact with data >> renWin->Render(); >> iren->Start(); >> >> // Clean up >> >> cube->Delete(); >> cubeMapper->Delete(); >> cubeActor->Delete(); >> camera->Delete(); >> renderer->Delete(); >> renWin->Delete(); >> iren->Delete(); >> >> return 0; >> } >> [image: 内嵌图片 1] >> >> >> 2013/9/13 Utkarsh Ayachit <[email protected]> >> >>> Float arrays cannot be directly mapped to colors. They need a LUT to >>> convert to color. If you want to pass RGB colors, create a >>> vtkUnsignedCharArray with 3 components instead. Then VTK can render >>> those colors directly without mapping. >>> >>> On Fri, Sep 13, 2013 at 10:55 AM, 庞庆源 <[email protected]> >>> wrote: >>> > scalararray is vtkFloatArray.I only call >>> > pointScalars->InsertTuple1(myId,velocity) for every point.never call >>> > SetNumberOfComponents();Is it the problem? >>> > >>> > >>> > 2013/9/13 Utkarsh Ayachit <[email protected]> >>> >> >>> >> WHat is the type of scalar array? If it's not an unsigned char array >>> with >>> >> 3 or 4 components, VTK will use a lookuptable to map the scalar to >>> colors. >>> >> >>> >> Utkarsh >>> >> >>> >> >>> >> On Fri, Sep 13, 2013 at 8:52 AM, 庞庆源 <[email protected]> >>> wrote: >>> >>> >>> >>> >>> >>> I write a simple reader,inheriting from vtkPolyDataAlgorithm.But >>> >>> SetScalars() cannot color the plane.When I test it use general vtk >>> >>> polydata->mapper->actor->renderer->renderwindow,I can see different >>> color at >>> >>> different point.Does someone know the reason?Thank you. >>> >>> -- >>> >>> 庞庆源 >>> >>> >>> >>> _______________________________________________ >>> >>> Powered by www.kitware.com >>> >>> >>> >>> Visit other Kitware open-source projects at >>> >>> http://www.kitware.com/opensource/opensource.html >>> >>> >>> >>> Please keep messages on-topic and check the ParaView Wiki at: >>> >>> http://paraview.org/Wiki/ParaView >>> >>> >>> >>> Follow this link to subscribe/unsubscribe: >>> >>> http://www.paraview.org/mailman/listinfo/paraview >>> >>> >>> >> >>> > >>> > >>> > >>> > -- >>> > 庞庆源 >>> >> >> >> >> -- >> 庞庆源 <[email protected]> >> > > > > -- > 庞庆源 <[email protected]> >
<<myreader4.png>>
_______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the ParaView Wiki at: http://paraview.org/Wiki/ParaView Follow this link to subscribe/unsubscribe: http://www.paraview.org/mailman/listinfo/paraview
