mitk::ColorBarAnnotation::ColorBarAnnotation()
{
  SetDrawAnnotations(true);

  SetDrawTickLabels(true);

  SetOrientationToVertical();

  SetMaxNumberOfColors(100);
  SetNumberOfLabels(4);

  SetAnnotationTextScaling(false);

  SetLookupTable(NULL);
}
Exemplo n.º 2
0
void mitk::LookupTableProperty::SetValue(const ValueType & value)
{
  SetLookupTable(value);
}
Exemplo n.º 3
0
bool Exporter::exportImageFormat(ImageDataObject & image, const QString & fileName)
{
    QString ext = QFileInfo(fileName).suffix().toLower();

    vtkSmartPointer<vtkImageWriter> writer;

    if (ext == "png")
    {
        writer = vtkSmartPointer<vtkPNGWriter>::New();
    }
    else if (ext == "jpg" || ext == "jpeg")
    {
        writer = vtkSmartPointer<vtkJPEGWriter>::New();
    }
    else if (ext == "bmp")
    {
        writer = vtkSmartPointer<vtkBMPWriter>::New();
    }

    if (!writer)
    {
        return false;
    }

    const auto scalars = image.dataSet()->GetPointData()->GetScalars();
    if (!scalars)
    {
        return false;
    }

    const auto components = scalars->GetNumberOfComponents();
    if (components != 1 && components != 3 && components != 4)
    {
        return false;
    }

    if (scalars->GetDataType() == VTK_UNSIGNED_CHAR)
    {
        writer->SetInputData(image.dataSet());
    }
    else
    {
        auto toUChar = vtkSmartPointer<ImageMapToColors>::New();
        toUChar->SetInputData(image.dataSet());

        auto lut = vtkSmartPointer<vtkLookupTable>::New();
        lut->SetNumberOfTableValues(0xFF);
        lut->SetHueRange(0, 0);
        lut->SetSaturationRange(0, 0);
        lut->SetValueRange(0, 1);

        ValueRange<> totalRange;
            
        for (int c = 0; c < components; ++c)
        {
            ValueRange<> range;
            scalars->GetRange(range.data(), c);
            totalRange.add(range);
        }

        toUChar->SetOutputFormat(
            components == 3 ? VTK_RGB :
            (components == 4 ? VTK_RGBA :
                VTK_LUMINANCE));

        toUChar->SetLookupTable(lut);

        writer->SetInputConnection(toUChar->GetOutputPort());
    }

    writer->SetFileName(fileName.toUtf8().data());
    writer->Write();

    return true;
}
Exemplo n.º 4
0
int main(int, char *[])
{

  const std::string file = "/home/mathieu/dev/cochleo/share/cochlee.wav";
  const audiofile audio(file);
  filterbank fb(audio.sample_frequency(),100,6000,1000);

  const auto xaxis = audio.time();
  const auto yaxis = fb.center_frequency();
  auto cochleo = fb.compute(audio.channel(0));
  normalization(cochleo);

  // Create the color palette  
  auto palette = vtkSmartPointer<vtkLookupTable>::New();
  palette->SetTableRange(0.0,1.0);
  palette->SetHueRange(0.67,0.);
  palette->SetSaturationRange(0.7,0.3);
  palette->Build();
     
  // Create a c-style rgb image
  const std::size_t width = xaxis.size();
  const std::size_t height = yaxis.size();
  std::vector<unsigned char> cImage(3*width*height);
  
  for(std::size_t i=0; i<width; ++i)
    for(std::size_t j=0; j<height; ++j)
      {
  	unsigned char* color = palette->MapValue(cochleo[i][j]);
  	cImage[3*(i+width*j)]   = color[0];
  	cImage[3*(i+width*j)+1] = color[1];
  	cImage[3*(i+width*j)+2] = color[2];
      }
  
  // Convert the c-style image to a vtkImageData
  auto imageImport = vtkSmartPointer<vtkImageImport>::New();
  imageImport->SetDataSpacing(0.07, 1, 1);
  imageImport->SetDataOrigin(0, 0, 0);
  imageImport->SetWholeExtent(0, width-1, 0, height-1, 0, 0);
  imageImport->SetDataExtentToWholeExtent();
  imageImport->SetDataScalarTypeToUnsignedChar();
  imageImport->SetNumberOfScalarComponents(3);
  imageImport->SetImportVoidPointer(cImage.data());
  imageImport->Update();
 
  // Create an actor
  auto actor = vtkSmartPointer<vtkImageActor>::New();
  actor->SetInput(imageImport->GetOutput());
  
  // Create a scalar bar
  auto scalarBar = vtkSmartPointer<vtkScalarBarActor>::New();
  scalarBar->SetLookupTable(palette);
  scalarBar->SetTitle("gain");
  scalarBar->SetNumberOfLabels(5);

  // Configure text of the scalar bar
  auto textBar = vtkSmartPointer<vtkTextProperty>::New();
  textBar->SetFontSize(10);
  scalarBar->SetTitleTextProperty(textBar);
  scalarBar->SetLabelTextProperty(textBar);
   
  // Setup renderer
  auto renderer = vtkSmartPointer<vtkRenderer>::New();
  renderer->AddActor(actor);
  renderer->AddActor(scalarBar);
  renderer->ResetCamera();
  
  // Setup render window
  auto renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
 
  // Setup render window interactor
  auto renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
  auto style = vtkSmartPointer<vtkInteractorStyleImage>::New();
 
  renderWindowInteractor->SetInteractorStyle(style);
 
  // Render and start interaction
  renderWindowInteractor->SetRenderWindow(renderWindow);
  renderWindowInteractor->Initialize();
  renderWindowInteractor->Start();
 
  return EXIT_SUCCESS;
}