<div class="gmail_quote">On Sun, Sep 18, 2011 at 6:39 AM, Martin Waitzbauer <span dir="ltr"><<a href="mailto:mazzok@gmx.at">mazzok@gmx.at</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hello, i want to write a small program, that is painting the tiles o a plane, if the user clicks the left mouse button<br>
<br>
i tried it like this (most parts taken from <a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/ColorCells" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/ColorCells</a>)<br>
<br>
KeyPressInteractorStyle is a self written class, doesnt do anything special than logging left mouse buttons, if the user clicks the left button than arraydata is being filled with a new value,and the window is rendered<br>

<br>
the method is like this<br>
virtual void OnLeftButtonDown(){<br>
                std::cout << "The left mouse key was pressed." << std::endl;<br>
                int r = rand() %2;<br>
                arraydata->SetValue(1,r);<br>
                this->GetInteractor()->GetRenderWindow()->Render();<br>
        }<br>
<br>
Unforrtuantly i wasnt able to make it do so!<br>
changes in the array arent displayed on the screen<br>
<br>
so my quetion is, how can i access the plane grid data<br>
(set by aPlane->GetOutput()->GetCellData()->SetScalars(cellData);) in a way, that changes , triggered by mouse events get displayed?<br>
<br>
Tahsnk alot!<br>
<br>
cheers,M<br>
<br>
int main...{<br>
 int resolution = 3;<br>
  vtkSmartPointer<vtkPlaneSource> aPlane =<br>
    vtkSmartPointer<vtkPlaneSource>::New();<br>
  aPlane->SetXResolution(resolution);<br>
  aPlane->SetYResolution(resolution);<br>
<br>
  // Create cell data<br>
  vtkSmartPointer<vtkFloatArray> cellData =<br>
    vtkSmartPointer<vtkFloatArray>::New();<br>
  for (int i = 0; i < resolution * resolution; i++)<br>
    {<br>
          cellData->InsertNextValue(0);<br>
  }<br>
<br>
  cellData->SetValue(5,2);<br>
<br>
  // Create a lookup table to map cell data to colors<br>
  vtkSmartPointer<vtkLookupTable> lut =<br>
    vtkSmartPointer<vtkLookupTable>::New();<br>
  int tableSize = std::max(resolution*resolution + 1, 10);<br>
  lut->SetNumberOfTableValues(tableSize);<br>
  lut->Build();<br>
<br>
  // Fill in a few known colors, the rest will be generated if needed<br>
  lut->SetTableValue(0     , 0     , 0     , 0, 1);  //Black<br>
  lut->SetTableValue(1, 0.8900, 0.8100, 0.3400, 1); // Banana<br>
  lut->SetTableValue(2, 1.0000, 0.3882, 0.2784, 1); // Tomato<br>
  lut->SetTableValue(3, 0.9608, 0.8706, 0.7020, 1); // Wheat<br>
  lut->SetTableValue(4, 0.9020, 0.9020, 0.9804, 1); // Lavender<br>
  lut->SetTableValue(5, 1.0000, 0.4900, 0.2500, 1); // Flesh<br>
  lut->SetTableValue(6, 0.5300, 0.1500, 0.3400, 1); // Raspberry<br>
  lut->SetTableValue(7, 0.9804, 0.5020, 0.4471, 1); // Salmon<br>
  lut->SetTableValue(8, 0.7400, 0.9900, 0.7900, 1); // Mint<br>
  lut->SetTableValue(9, 0.2000, 0.6300, 0.7900, 1); // Peacock<br>
<br>
  aPlane->Update(); // Force an update so we can set cell data<br>
  aPlane->GetOutput()->GetCellData()->SetScalars(cellData);<br>
  // Setup actor and mapper<br>
  vtkSmartPointer<vtkPolyDataMapper> mapper =<br>
    vtkSmartPointer<vtkPolyDataMapper>::New();<br>
  mapper->SetInputConnection(aPlane->GetOutputPort());<br>
  mapper->SetScalarRange(0, tableSize - 1);<br>
<br>
  mapper->SetLookupTable(lut);<br>
<br>
  vtkSmartPointer<vtkActor> actor =<br>
    vtkSmartPointer<vtkActor>::New();<br>
  actor->SetMapper(mapper);<br>
<br>
  // Setup render window, renderer, and interactor<br>
  vtkSmartPointer<vtkRenderer> renderer =<br>
    vtkSmartPointer<vtkRenderer>::New();<br>
  vtkSmartPointer<vtkRenderWindow> renderWindow =<br>
    vtkSmartPointer<vtkRenderWindow>::New();<br>
  renderWindow->AddRenderer(renderer);<br>
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =<br>
      vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>
  renderWindowInteractor->SetRenderWindow(renderWindow);<br>
  renderer->AddActor(actor);<br>
  renderer->SetBackground(.1,.2,.3);<br>
  renderWindowInteractor->Initialize();<br>
<br>
//set up interactor<br>
  KeyPressInteractorStyle * ss = KeyPressInteractorStyle::New();<br>
<br>
  renderWindowInteractor->SetInteractorStyle(ss);<br>
  ss->Setarraydata(cellData);<br>
<br>
  renderWindowInteractor->Start();<br>
}<br><br></blockquote><div class="gmail_quote"><br></div>This type of question is better posed to the vtk-users mailing list. I suggest sending it there, as well as modifying the code you posted to be fully compilable, so that a reader can simply copy and paste, compile, and see what is going on. You can also simply the code as much as possible - perhaps use a more standard lookup table instead of the manual one you are creating. It psychologically makes it look like less code so people are more inclined to look at it :)</div>
<div class="gmail_quote"><br><div>David </div></div><br>