示例#1
0
void ColorEditor::onButtonClick()
{
  // On OSX, once the dialog opens, the tree view loses focus and thus
  // this editor is destroyed.  Therefore everything we do in this
  // function after dialog->exec() should only use variables on the
  // stack, not member variables.

  ColorProperty* prop = property_;
  QColor original_color = prop->getColor();

  QColorDialog* dialog = new QColorDialog( color_, this );

  // On Linux these two connections are redundant, because the editor
  // lives while the dialog is up.  This should not hurt anything,
  // just be slightly inefficient.  On OSX, only the connection to the
  // Property will exist because this editor will be destroyed.

  connect( dialog, SIGNAL( currentColorChanged( const QColor& )),
           property_, SLOT( setColor( const QColor& )));
  connect( dialog, SIGNAL( currentColorChanged( const QColor& )),
           this, SLOT( setColor( const QColor& )));

  if( dialog->exec() != QDialog::Accepted )
  {
#ifdef Q_OS_MAC
    prop->setColor( original_color );
#else
    setColor( original_color );
#endif
  }
}
void CommunitySpace::getFinalAssignation( string group_prop_name ) {
    int i;
    int level = 1;
    IntegerProperty* g_assignation = originalGraph->getLocalProperty<IntegerProperty>(group_prop_name);
    ColorProperty* color = originalGraph->getLocalProperty<ColorProperty>("viewColor");
    int communities = theGraph->numberOfNodes();
    //cout << "Calculating final assignation for " << communities << " communities." << endl;
    string group_name("");
    for ( i = 0; i < communities; i++ ) {
        group_name.append(group_prefix).append("_").append(static_cast<ostringstream*>(&(ostringstream()<<i))->str() );
        hierarchy[i] = originalGraph->addSubGraph(group_name);
        group_name = "";
    }
    calculateColorTable(communities);
    color->setAllEdgeValue(Color(0,0,0,5));
    Iterator<node>* nodes = originalGraph->getNodes();
    while ( nodes->hasNext() ) {
        node n = nodes->next();
        i = n.id;
        int index = finalAssignation[0][i];
        while ( level < (int)finalAssignation.size() ) {
            int nindex = finalAssignation[level][index];
            index = nindex;
            level++;
        }
        level = 1;
        addNodeToGroup(index, n, g_assignation, color);
    }
    delete nodes;
}
示例#3
0
TEST( ColorProperty, default_value )
{
  ColorProperty* qp = new ColorProperty();
  QColor color = qp->getColor();
  EXPECT_EQ( 0, color.red() );
  EXPECT_EQ( 0, color.green() );
  EXPECT_EQ( 0, color.blue() );
}
示例#4
0
TEST( ColorProperty, set_string_limits )
{
  ColorProperty* qp = new ColorProperty();
  qp->setValue( QString( "-1;2000;3" ));

  QColor color = qp->getColor();
  EXPECT_EQ( 0, color.red() );
  EXPECT_EQ( 255, color.green() );
  EXPECT_EQ( 3, color.blue() );
}
示例#5
0
TEST( ColorProperty, set_value_events )
{
  ColorProperty p;

  MockPropertyChangeReceiver r( &p );
  p.connect( &p, SIGNAL( aboutToChange() ), &r, SLOT( aboutToChange() ));
  p.connect( &p, SIGNAL( changed() ), &r, SLOT( changed() ));

  p.setColor( QColor( 1, 2, 3 ));
  EXPECT_EQ( " aboutToChange, v=0; 0; 0 changed, v=1; 2; 3", r.result().toStdString() );
}
示例#6
0
TEST( ColorProperty, set_and_get )
{
  ColorProperty* qp = new ColorProperty();
  QColor color( 1, 2, 3 );
  qp->setColor( color );

  QColor color2 = qp->getColor();
  EXPECT_EQ( 1, color2.red() );
  EXPECT_EQ( 2, color2.green() );
  EXPECT_EQ( 3, color2.blue() );
}
示例#7
0
//=================================================================================
PropertyInterface* ColorProperty::clonePrototype(Graph * g, const std::string& n) {
  if( !g )
    return 0;

  // allow to get an unregistered property (empty name)
  ColorProperty * p = n.empty()
                      ? new ColorProperty(g) : g->getLocalProperty<ColorProperty>( n );
  p->setAllNodeValue( getNodeDefaultValue() );
  p->setAllEdgeValue( getEdgeDefaultValue() );
  return p;
}
示例#8
0
// That function sets some visual properties on a complete tree whose depth equals 5
void setTreeVisualProperties(Graph *tree) {

  // First compute a layout, we use the Bubble Tree algorithm
  LayoutProperty *viewLayout = tree->getProperty<LayoutProperty>("viewLayout");
  std::string errMsg;
  tree->applyPropertyAlgorithm("Bubble Tree", viewLayout, errMsg);

  // Then apply Auto Sizing on the nodes
  SizeProperty *viewSize = tree->getProperty<SizeProperty>("viewSize");
  tree->applyPropertyAlgorithm("Auto Sizing", viewSize, errMsg);

  // Labels the node with their id
  StringProperty *viewLabel = tree->getProperty<StringProperty>("viewLabel");
  for (auto n : tree->nodes()) {
    viewLabel->setNodeValue(n, QStringToTlpString(QString::number(n.id)));
  }

  // Add a border to the nodes, keep the default color who is black
  DoubleProperty *viewBorderWidth = tree->getProperty<DoubleProperty>("viewBorderWidth");
  viewBorderWidth->setAllNodeValue(1);

  // Build some maps to set shapes and colors according to the dag level of a node
  std::vector<int> glyphsMap;
  glyphsMap.push_back(tlp::NodeShape::Square);
  glyphsMap.push_back(tlp::NodeShape::Circle);
  glyphsMap.push_back(tlp::NodeShape::RoundedBox);
  glyphsMap.push_back(tlp::NodeShape::Hexagon);
  glyphsMap.push_back(tlp::NodeShape::Star);
  glyphsMap.push_back(tlp::NodeShape::Ring);

  std::vector<Color> colorsMap;
  colorsMap.push_back(Color::Red);
  colorsMap.push_back(Color::Azure);
  colorsMap.push_back(Color::Lemon);
  colorsMap.push_back(Color::SpringGreen);
  colorsMap.push_back(Color::Apricot);
  colorsMap.push_back(Color::Magenta);

  // Compute the Dag Level metric, the value of each node will correspond
  // to their layer id in the tree
  DoubleProperty dagLevel(tree);
  tree->applyPropertyAlgorithm("Dag Level", &dagLevel, errMsg);

  // Sets different shapes and colors for each layer of the tree
  IntegerProperty *viewShape = tree->getProperty<IntegerProperty>("viewShape");
  ColorProperty *viewColor = tree->getProperty<ColorProperty>("viewColor");
  for (auto n : tree->nodes()) {
    viewShape->setNodeValue(n, glyphsMap[int(dagLevel.getNodeValue(n))]);
    viewColor->setNodeValue(n, colorsMap[int(dagLevel.getNodeValue(n))]);
  }
}
示例#9
0
TEST( ColorProperty, set_string )
{
  ColorProperty* qp = new ColorProperty();
  qp->setValue( QString( "1;2;3" ));

  QColor color = qp->getColor();
  EXPECT_EQ( 1, color.red() );
  EXPECT_EQ( 2, color.green() );
  EXPECT_EQ( 3, color.blue() );

  qp->setValue( QString( "chubby!" ));

  color = qp->getColor();
  EXPECT_EQ( 1, color.red() );
  EXPECT_EQ( 2, color.green() );
  EXPECT_EQ( 3, color.blue() );
}
示例#10
0
//=====================================================
void Window::draw(node n, float lod) {
    ColorProperty* color = glGraphInputData->getElementColor();
    ColorProperty* colorBorder = glGraphInputData->getElementBorderColor();
    string textureName = glGraphInputData->getElementTexture()->getNodeValue(n);

    if(textureName!="")
        textureName=glGraphInputData->parameters->getTexturePath()+textureName;

    _border.setColor(colorBorder->getNodeValue(n));
    _titleRec.setColor(colorBorder->getNodeValue(n));

    _center.setFillColor(color->getNodeValue(n));
    _center.setTextureName(textureName);
    _center.draw(lod, NULL);
    _titleRec.draw(lod, NULL);
    _border.draw(lod, NULL);
}
示例#11
0
  bool exportGraph(ostream &os) {

    os << "graph [" << endl;
    os << "directed 1" << endl;
    os << "version 2" << endl;

    LayoutProperty *layout = graph->getProperty<LayoutProperty>("viewLayout");
    StringProperty *label = graph->getProperty<StringProperty>("viewLabel");
    //    IntegerProperty *shape =getProperty<IntegerProperty>(graph->getPropertyManager(),"viewShape");
    ColorProperty *colors = graph->getProperty<ColorProperty>("viewColor");
    SizeProperty  *sizes = graph->getProperty<SizeProperty>("viewSize");
    //Save Nodes
    Iterator<node> *itN=graph->getNodes();

    if (itN->hasNext())  {

      for (; itN->hasNext();) {
        node itn=itN->next();
        os << "node [" << endl;
        os << "id "<< itn.id << endl ;
        os << "label \"" << convert(label->getNodeValue(itn)) << "\"" << endl;
        os << "graphics [" << endl;
        printCoord(os,layout->getNodeValue(itn));
        printSize(os,sizes->getNodeValue(itn));
        os << "type \"rectangle\"" << endl;
        os << "width 0.12" << endl;
        os << "fill \"#"<< hex << setfill('0') << setw(2) <<(int)colors->getNodeValue(itn).getR()
           << hex << setfill('0') << setw(2) <<(int)colors->getNodeValue(itn).getG()
           << hex << setfill('0') << setw(2) <<(int)colors->getNodeValue(itn).getB() << "\""<< endl;

        //      os << "outline \"#"<< hex << setfill('0') << setw(2) <<(int)colors->getNodeValue(itn).getR()
        //         << hex << setfill('0') << setw(2) <<(int)colors->getNodeValue(itn).getG()
        //         << hex << setfill('0') << setw(2) <<(int)colors->getNodeValue(itn).getB() << "\""<< endl;

        os << "outline \"#000000\"" << endl;
        os << dec << setfill(' ') << setw(6) << "]" << endl;
        os << ']' << endl;
      }
    }

    delete itN;

    //Save edges
    Iterator<edge> *itE=graph->getEdges();

    for (; itE->hasNext();) {
      edge ite=itE->next();
      os << "edge [" << endl;
      os << "source " << graph->source(ite).id << endl;
      os << "target " << graph->target(ite).id << endl;
      os << "id " << ite.id << endl;
      os << "label \"" << label->getEdgeValue(ite) << "\"" << endl;
      os << "graphics [" << endl;
      os << "type \"line\"" << endl;
      os << "arrow \"last\"" << endl;
      os << "width 0.1" << endl;
      os << "Line [" << endl;
      vector<Coord> lcoord;
      vector<Coord>::const_iterator it;
      lcoord=layout->getEdgeValue(ite);

      if (!lcoord.empty()) {
        node itn=graph->source(ite);
        printPoint(os,layout->getNodeValue(itn));
      }

      for (it=lcoord.begin(); it!=lcoord.end(); ++it) {
        printPoint(os,*it);
      }

      if (!lcoord.empty()) {
        node itn=graph->target(ite);
        printPoint(os,layout->getNodeValue(itn));
      }

      os << "]" << endl;
      os << "]" << endl;
      os << "]" << endl;
    }

    delete itE;
    os << "]" << endl;
    return true;
  }
void mitk::VolumeDataVtkMapper3D::GenerateDataForRenderer( mitk::BaseRenderer *renderer )
{
  SetVtkMapperImmediateModeRendering(m_BoundingBoxMapper);

  mitk::Image *input = const_cast< mitk::Image * >( this->GetInput() );
  if ( !input || !input->IsInitialized() )
    return;

  vtkRenderWindow* renderWindow = renderer->GetRenderWindow();

  bool volumeRenderingEnabled = true;

  if (this->IsVisible(renderer)==false ||
      this->GetDataNode() == NULL ||
      dynamic_cast<mitk::BoolProperty*>(GetDataNode()->GetProperty("volumerendering",renderer))==NULL ||
      dynamic_cast<mitk::BoolProperty*>(GetDataNode()->GetProperty("volumerendering",renderer))->GetValue() == false
    )
  {
    volumeRenderingEnabled = false;

    // Check if a bounding box should be displayed around the dataset
    // (even if volume rendering is disabled)
    bool hasBoundingBox = false;
    this->GetDataNode()->GetBoolProperty( "bounding box", hasBoundingBox );

    if ( !hasBoundingBox )
    {
      m_BoundingBoxActor->VisibilityOff();
    }
    else
    {
      m_BoundingBoxActor->VisibilityOn();

      const BoundingBox::BoundsArrayType &bounds =
        input->GetTimeSlicedGeometry()->GetBounds();

      m_BoundingBox->SetBounds(
        bounds[0], bounds[1],
        bounds[2], bounds[3],
        bounds[4], bounds[5] );

      ColorProperty *colorProperty;
      if ( this->GetDataNode()->GetProperty(
        colorProperty, "color" ) )
      {
        const mitk::Color &color = colorProperty->GetColor();
        m_BoundingBoxActor->GetProperty()->SetColor(
          color[0], color[1], color[2] );
      }
      else
      {
        m_BoundingBoxActor->GetProperty()->SetColor(
          1.0, 1.0, 1.0 );
      }
    }
  }

  // Don't do anything if VR is disabled
  if ( !volumeRenderingEnabled )
  {
    m_VolumeLOD->VisibilityOff();
    return;
  }
  else
  {
        mitk::VtkVolumeRenderingProperty* vrp=dynamic_cast<mitk::VtkVolumeRenderingProperty*>(GetDataNode()->GetProperty("volumerendering configuration",renderer));
        if(vrp)
        {
          int renderingValue = vrp->GetValueAsId();

          switch(renderingValue)
          {
              case  VTK_VOLUME_RAY_CAST_MIP_FUNCTION:
              {
                  vtkVolumeRayCastMIPFunction* mipFunction = vtkVolumeRayCastMIPFunction::New();
                  m_HiResMapper->SetVolumeRayCastFunction(mipFunction);
                  mipFunction->Delete();
                  MITK_INFO <<"in switch" <<std::endl;
                  break;
              }

              case VTK_RAY_CAST_COMPOSITE_FUNCTION:
              {
                  vtkVolumeRayCastCompositeFunction* compositeFunction = vtkVolumeRayCastCompositeFunction::New();
                  compositeFunction->SetCompositeMethodToClassifyFirst();
                  m_HiResMapper->SetVolumeRayCastFunction(compositeFunction);
                  compositeFunction->Delete();
                  break;
              }
              default:
                  MITK_ERROR <<"Warning: invalid volume rendering option.  " << std::endl;

          }
        }
    m_VolumeLOD->VisibilityOn();
  }

  this->SetPreferences();
/*
  switch ( mitk::RenderingManager::GetInstance()->GetNextLOD( renderer ) )
  {
  case 0:
    m_VolumeLOD->SetSelectedLODID(m_MedResID);  m_LowResID );
    break;

  default:
  case 1:
    m_VolumeLOD->SetSelectedLODID( m_HiResID );
    break;
  }
*/
  m_VolumeLOD->SetSelectedLODID( m_HiResID );

  assert(input->GetTimeSlicedGeometry());

  const Geometry3D* worldgeometry = renderer->GetCurrentWorldGeometry();
  if(worldgeometry==NULL)
  {
    GetDataNode()->SetProperty("volumerendering",mitk::BoolProperty::New(false));
    return;
  }

  vtkImageData *inputData = input->GetVtkImageData( this->GetTimestep() );
  if(inputData==NULL)
    return;


  m_ImageCast->SetInput( inputData );

  //If mask exists, process mask before resampling.
  if (this->m_Mask)
  {
    this->m_ImageMaskFilter->SetImageInput(this->m_UnitSpacingImageFilter->GetOutput());
    this->m_Resampler->SetInput(this->m_ImageMaskFilter->GetOutput());
    this->m_HiResMapper->SetInput(this->m_ImageMaskFilter->GetOutput());
  }
  else
  {
    this->m_Resampler->SetInput(this->m_UnitSpacingImageFilter->GetOutput());
    this->m_HiResMapper->SetInput(this->m_UnitSpacingImageFilter->GetOutput());
  }

  this->UpdateTransferFunctions( renderer );

  vtkRenderWindowInteractor *interactor = renderWindow->GetInteractor();

  float frameRate;
  if( this->GetDataNode()->GetFloatProperty( "framerate", frameRate ) && frameRate > 0 && frameRate <= 60)
  {
    interactor->SetDesiredUpdateRate(  frameRate );
    interactor->SetStillUpdateRate( frameRate );
  }
  else if( frameRate > 60 )
  {
    this->GetDataNode()->SetProperty( "framerate",mitk::FloatProperty::New(60));
    interactor->SetDesiredUpdateRate(  60 );
    interactor->SetStillUpdateRate( 60 );
  }
  else
  {
    this->GetDataNode()->SetProperty( "framerate",mitk::FloatProperty::New(0.00001));
    interactor->SetDesiredUpdateRate(  0.00001 );
    interactor->SetStillUpdateRate( 0.00001 );
  }

  if ( m_RenderWindowInitialized.find( renderWindow ) == m_RenderWindowInitialized.end() )
  {
    m_RenderWindowInitialized.insert( renderWindow );

//    mitk::RenderingManager::GetInstance()->SetNextLOD( 0, renderer );

    mitk::RenderingManager::GetInstance()->SetShading( true, 0 );
    mitk::RenderingManager::GetInstance()->SetShading( true, 1 );
    //mitk::RenderingManager::GetInstance()->SetShading( true, 2 );

    mitk::RenderingManager::GetInstance()->SetShadingValues(
      m_VolumePropertyHigh->GetAmbient(),
      m_VolumePropertyHigh->GetDiffuse(),
      m_VolumePropertyHigh->GetSpecular(),
      m_VolumePropertyHigh->GetSpecularPower());

    mitk::RenderingManager::GetInstance()->SetClippingPlaneStatus(false);
  }

  this->SetClippingPlane( interactor );
}
示例#13
0
int main(int, char **) {

  /*
   * Let's create the following graph
   *
   *      A
   *    /   \
   *  B       C
   *   \     /
   *    D - E
   */

  /*
   Initialize the library and load all plugins
   */
  tlp::initTulipLib();
  PluginLoaderTxt loadertxt;
  PluginLibraryLoader::loadPlugins(&loadertxt);

  // create a new graph
  Graph *myGraph = tlp::newGraph();

  node a = myGraph->addNode();
  node b = myGraph->addNode();
  node c = myGraph->addNode();
  node d = myGraph->addNode();
  node e = myGraph->addNode();

  myGraph->addEdge(a, b);
  myGraph->addEdge(a, c);
  myGraph->addEdge(b, d);
  myGraph->addEdge(c, e);
  myGraph->addEdge(d, e);

  // now in color. 'viewColor' is the Tulip GUI's default color property, so when we load it we will
  // see the color immediately
  // If 'viewColor' did not exist before, this creates it.
  ColorProperty *color = myGraph->getProperty<ColorProperty>("viewColor");
  color->setNodeValue(a, Color(255, 0, 0));
  color->setNodeValue(b, Color(0, 255, 0));
  color->setNodeValue(c, Color(0, 0, 255));
  color->setNodeValue(d, Color(255, 0, 0));
  color->setNodeValue(e, Color(0, 255, 0));
  // hey look, this is a 3-coloration :)

  // set the label of the nodes (again, with Tulip's default label property)
  StringProperty *label = myGraph->getProperty<StringProperty>("viewLabel");
  label->setNodeValue(a, "A");
  label->setNodeValue(b, "B");
  label->setNodeValue(c, "C");
  label->setNodeValue(d, "D");
  label->setNodeValue(e, "E");

  DoubleProperty *metric = myGraph->getProperty<DoubleProperty>("degree");

  // if the degree plugin is available, let's call it.
  if (tlp::PluginLister::instance()->pluginExists("Degree")) {
    // now compute the degree of the nodes.
    string errorMessage;
    // this calls the Tulip plugin 'Degree'.
    bool success = myGraph->applyPropertyAlgorithm("Degree", metric, errorMessage);

    if (!success) {
      std::cout << errorMessage << std::endl;
    }
  } else {
    std::cout << "could not find the plugin, computing" << std::endl;
    for (auto n : myGraph->nodes()) {
      metric->setNodeValue(n, myGraph->deg(n));
    }
  }

  // output the degree of node a;
  std::cout << metric->getNodeValue(a) << std::endl;

  // saveGraph is a shortcut ofr exportGraph that uses the TLP export.
  tlp::saveGraph(myGraph, "mygraph.tlp");

  return EXIT_SUCCESS;
}
示例#14
0
void LabelsRenderer::renderGraphNodesLabels(Graph *graph, const Camera &camera, const Color &selectionColor) {

  initFont();

  BooleanProperty *viewSelection = graph->getProperty<BooleanProperty>("viewSelection");
  ColorProperty *viewLabelColor = graph->getProperty<ColorProperty>("viewLabelColor");
  StringProperty *viewLabel = graph->getProperty<StringProperty>("viewLabel");

  Vec4i viewport = camera.getViewport();

  vector<vector<Vec2f> > renderedLabelsScrRect;
  vector<BoundingBox> renderedLabelsScrBB;

  NVGcontext* vg = NanoVGManager::instance()->getNanoVGContext();

  nvgBeginFrame(vg, camera.getViewport()[0], camera.getViewport()[1], camera.getViewport()[2], camera.getViewport()[3], 1.0);

  for (vector<node>::iterator it = _labelsToRender[graph].begin() ; it != _labelsToRender[graph].end() ; ++it) {

    if (_nodeLabelAspectRatio[graph].find(*it) == _nodeLabelAspectRatio[graph].end()) {
      continue;
    }

    BoundingBox nodeBB = labelBoundingBoxForNode(graph, *it);

    BoundingBox textBB = getLabelRenderingBoxScaled(nodeBB, _nodeLabelAspectRatio[graph][*it]);

    if (!_labelsScaled) {

      adjustTextBoundingBox(textBB, camera, _minSize, _maxSize, _nodeLabelNbLines[graph][*it]);
    }

    bool canRender = true;

    if (_occlusionTest) {

      if (!camera.hasRotation()) {
        BoundingBox textScrBB;
        textScrBB.expand(Vec3f(computeScreenPos(camera.transformMatrixBillboard(), viewport, textBB[0]), 0));
        textScrBB.expand(Vec3f(computeScreenPos(camera.transformMatrixBillboard(), viewport, textBB[1]), 0));

        for (size_t i = 0 ; i < renderedLabelsScrBB.size() ; ++i) {
          if (textScrBB.intersect(renderedLabelsScrBB[i])) {
            canRender = false;
            break;
          }
        }

        if (canRender) {
          renderedLabelsScrBB.push_back(textScrBB);
        }

      } else {
        vector<Vec2f> textScrRect;
        textScrRect.push_back(computeScreenPos(camera.transformMatrix(), viewport, textBB[0]));
        textScrRect.push_back(computeScreenPos(camera.transformMatrix(), viewport, Vec3f(textBB[0][0]+textBB.width(), textBB[0][1], textBB[0][2])));
        textScrRect.push_back(computeScreenPos(camera.transformMatrix(), viewport, textBB[1]));
        textScrRect.push_back(computeScreenPos(camera.transformMatrix(), viewport, Vec3f(textBB[0][0], textBB[0][1]+textBB.height(), textBB[0][2])));

        for (size_t i = 0 ; i < renderedLabelsScrRect.size() ; ++i) {
          if (convexPolygonsIntersect(textScrRect, renderedLabelsScrRect[i])) {
            canRender = false;
            break;
          }
        }

        if (canRender) {
          renderedLabelsScrRect.push_back(textScrRect);
        }
      }
    }

    if (canRender) {

      Vec2f textBBMinScr = computeScreenPos(camera.transformMatrix(), viewport, textBB[0]);
      Vec2f textBBMaxScr = computeScreenPos(camera.transformMatrix(), viewport, textBB[1]);
      BoundingBox bb;
      bb.expand(Vec3f(textBBMinScr[0], viewport[3] - textBBMinScr[1]));
      bb.expand(Vec3f(textBBMaxScr[0], viewport[3] - textBBMaxScr[1]));

      renderText(vg, viewLabel->getNodeValue(*it), bb, viewSelection->getNodeValue(*it) ? selectionColor : viewLabelColor->getNodeValue(*it));

    }

  }

  nvgEndFrame(vg);
}