实现效果:
代码如下:
double leftview[4] = {0,0, 0.33,1};
double midview[4] = {0.33,0, 0.66,1};
double rightview[4] = {0.66,0, 1.0,1};
int bins = 256;
int comps = 1;
vtkSmartPointer
reader->SetFileName("d:/lena.jpg");
reader->Update();
vtkSmartPointer
actor1->GetMapper()->SetInputConnection(reader->GetOutputPort());
vtkSmartPointer
render1->AddActor(actor1);
render1->SetViewport(leftview);
render1->ResetCamera();
render1->SetBackground(0,1,0);
vtkSmartPointer
lum->SetInputConnection(reader->GetOutputPort());
lum->Update();
vtkSmartPointer
actorgray->GetMapper()->SetInputConnection(lum->GetOutputPort());
vtkSmartPointer
rendergray->AddActor(actorgray);
rendergray->SetViewport(midview);
rendergray->ResetCamera();
rendergray->SetBackground(1,0,0);
vtkSmartPointer
his->SetInputData(lum->GetOutput());
his->SetComponentExtent(0, bins-1, 0,0,0,0);
his->SetComponentOrigin(0,0,0);
his->SetComponentSpacing(256.0/bins, 0,0);
his->Update();
vtkSmartPointer
freq->SetNumberOfComponents(1);
int *output = static_cast<int*>(his->GetOutput()->GetScalarPointer());
for(int j=0; j
for(int i=0; i
freq->InsertNextTuple1(*output);
output++;
}
}
vtkSmartPointer
dobj->GetFieldData()->AddArray(freq);
vtkSmartPointer
actor2->SetInput(dobj);
actor2->SetTitle("histogram");
actor2->GetProperty()->SetColor(1,1,1);
actor2->GetLegendActor()->SetNumberOfEntries(dobj->GetFieldData()->GetArray(0)->GetNumberOfTuples());
actor2->LegendVisibilityOff();
actor2->LabelVisibilityOff();
double colors[3][3] = {{1,0,0},{0,1,0},{0,0,1}};
for(int i =0;i
actor2->SetBarColor(i, colors[0]);
}
vtkSmartPointer
render2->AddActor(actor2);
render2->SetViewport(rightview);
render2->ResetCamera();
render2->SetBackground(0,0,1);
pRenderWindow->AddRenderer(render1);
pRenderWindow->AddRenderer(rendergray);
pRenderWindow->AddRenderer(render2);