void SHistogram::updating() { this->stopping(); ::fwData::Histogram::csptr histogram = this->getInput< ::fwData::Histogram>(s_HISTOGRAM_INPUT); ::fwData::Histogram::fwHistogramValues values = histogram->getValues(); m_layer = new QGraphicsItemGroup(); if (!values.empty()) { // Update color with opacity QColor color = m_color.color(); color.setAlphaF( m_opacity ); m_color.setColor( color ); const float min = histogram->getMinValue(); const float binsWidth = histogram->getBinsWidth(); // Initialize the path with a start point: // The value preceding the current value that we'll use to build the arcs of the path Point2DType startPoint = this->mapAdaptorToScene(Point2DType(min, values[0]), m_xAxis, m_yAxis); Point2DType pair; QBrush brush = QBrush(m_color.color()); // Build the graphic items: const int nbValues = (int)values.size(); for(int i = 1; i < nbValues; ++i) { pair = this->mapAdaptorToScene(Point2DType(min + i * binsWidth, values[i]), m_xAxis, m_yAxis); QPainterPath painter( QPointF(startPoint.first, 0) ); painter.lineTo( startPoint.first, startPoint.second ); painter.lineTo( pair.first, pair.second ); painter.lineTo( pair.first, 0 ); QGraphicsPathItem* item = new QGraphicsPathItem( painter ); item->setPath( painter ); item->setBrush( brush ); item->setPen( Qt::NoPen ); item->setCacheMode( QGraphicsItem::DeviceCoordinateCache ); m_layer->addToGroup( item ); startPoint = pair; } // Adjust the layer's position and zValue depending on the associated axis m_layer->setPos(m_xAxis->getOrigin(), m_yAxis->getOrigin()); m_layer->setZValue(m_zValue); // Add to the scene the unique item which gather the whole set of rectangle graphic items: this->getScene2DRender()->getScene()->addItem( m_layer ); } }
IAdaptor::Point2DType IAdaptor::mapSceneToAdaptor(Point2DType _xy, ::scene2D::data::Axis::sptr _xAxis, ::scene2D::data::Axis::sptr _yAxis ) { // Do the reverse operation of the mapAdaptorToScene function double x, y; if (_xAxis->getScaleType() == "LOG") { x = 10 * exp( _xy.first ) / _xAxis->getScale(); } else { x = ( _xy.first ) / _xAxis->getScale(); } if (_yAxis->getScaleType() == "LOG") { y = 10 * ( _xy.second ) / _yAxis->getScale(); } else { y = _xy.second / _yAxis->getScale(); } return Point2DType( x , y ); }