22 #include <vtkColorTransferFunction.h>
23 #include <vtkImageAccumulate.h>
24 #include <vtkImageData.h>
25 #include <vtkPiecewiseFunction.h>
26 #include <vtkVolume.h>
27 #include <vtkVolumeProperty.h>
35 #define axl_BIN_WIDTH 8
77 void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
108 void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
182 void resize(
const QSize& size);
196 class axlVolumeDiscreteEditorPrivate
214 QRadioButton *log_radio;
215 QRadioButton *scl_radio;
216 QRadioButton *shd_radio;
260 qreal a_x = +h_w/s_w;
261 qreal a_y = -h_h/s_h;
262 qreal b_x = h_x-(h_w/s_w)*s_x;
263 qreal b_y = (s_h*(h_y+h_h)+h_h*s_y)/s_h;
265 return QPointF(a_x*x+b_x, a_y*y+b_y);
283 qreal a_x = +h_w/s_w;
284 qreal a_y = -h_h/s_h;
285 qreal b_x = h_x-(h_w/s_w)*s_x;
286 qreal b_y = (s_h*(h_y+h_h)+h_h*s_y)/s_h;
288 return QPointF(a_x*x+b_x, a_y*y+b_y);
313 qreal a_x = +s_w/h_w;
314 qreal a_y = -s_h/h_h;
315 qreal b_x = s_x-(s_w/h_w)*h_x;
316 qreal b_y = (s_h*(h_y+h_h)+h_h*s_y)/h_h;
318 return QPointF(a_x*x+b_x, a_y*y+b_y);
336 qreal a_x = +s_w/h_w;
337 qreal a_y = -s_h/h_h;
338 qreal b_x = s_x-(s_w/h_w)*h_x;
339 qreal b_y = (s_h*(h_y+h_h)+h_h*s_y)/h_h;
341 return QPointF(a_x*x+b_x, a_y*y+b_y);
355 this->setFlag(QGraphicsItem::ItemIsMovable,
true);
356 this->setFlag(QGraphicsItem::ItemIsSelectable,
true);
358 this->setCursor(Qt::ArrowCursor);
371 painter->setRenderHints(QPainter::Antialiasing,
true);
373 if(this->isSelected())
374 painter->setPen(Qt::magenta);
376 painter->setPen(QColor(0x55, 0x55, 0x55));
378 painter->setBrush(this->
background_color); painter->drawEllipse(-10.0, -10.0, 20.0, 20.0);
379 painter->setBrush(this->
foreground_color); painter->drawEllipse(-05.0, -05.0, 10.0, 10.0);
384 return QRectF(-10.0, -10.0, 20.0, 20.0);
400 QGraphicsItem::mouseMoveEvent(event);
416 this->brush = QColor::fromRgb(255, 0, 0, 128);
419 this->point_count = 0;
429 qreal h = vertex->scene()->sceneRect().height();
430 qreal y = vertex->scenePos().y();
445 return (v1->pos().x() < v2->pos().x());
452 vertex->setParentItem(
this);
459 QPointF value = point;
461 if (value.y() < rect.y())
462 value.setY(rect.y());
464 if(value.y() > rect.height())
465 value.setY(rect.height());
477 color->RemoveAllPoints();
480 opacity->RemoveAllPoints();
488 delete [] this->points;
492 this->point_count = this->
vertices.size()+4;
493 this->points =
new QPointF[this->point_count];
495 points[0] = QPointF(0, this->scene()->sceneRect().height());
496 points[1] = QPointF(0, this->
vertices.first()->pos().y());
498 QLinearGradient gradient(0, 0, this->scene()->sceneRect().width(), 0.0);
499 gradient.setColorAt(0, axlVolumeDiscreteEditorTableColor(this->
vertices.first()));
501 for(
int i = 0 ; i < this->
vertices.count() ; i++) {
503 points[i+2] = this->
vertices.at(i)->pos();
505 qreal x = this->
vertices.at(i)->pos().x();
506 qreal w = this->scene()->sceneRect().width();
515 gradient.setColorAt(r, axlVolumeDiscreteEditorTableColor(this->
vertices.at(i)));
523 color->AddRGBPoint(value.x(),
524 this->
vertices.at(i)->foreground_color.redF(),
525 this->
vertices.at(i)->foreground_color.greenF(),
526 this->
vertices.at(i)->foreground_color.blueF());
528 opacity->AddPoint(value.x(), value.y());
533 points[this->
vertices.count()+2] = QPointF(this->scene()->sceneRect().width(), this->
vertices.last()->pos().y());
534 points[this->
vertices.count()+3] = QPointF(this->scene()->sceneRect().width(), this->scene()->sceneRect().height());
536 gradient.setColorAt(1.0, axlVolumeDiscreteEditorTableColor(this->
vertices.last()));
538 this->brush = QBrush(gradient);
540 QGraphicsItem::update();
547 static_cast<vtkVolume *
>(this->
actor->
vol())->Update();
563 painter->setPen(Qt::NoPen);
564 painter->setBrush(this->brush);
565 painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
566 painter->setRenderHints(QPainter::Antialiasing,
true);
567 painter->drawPolygon(this->points, this->point_count);
572 if(!this->point_count)
575 return QRectF(this->points[0].x(), 0.0, this->points[this->point_count-1].x(), this->scene()->sceneRect().height());
587 this->use_log =
true;
588 this->use_scl =
false;
595 this->addItem(this->
table);
596 this->setBackgroundBrush(QColor(0x00, 0x00, 0x00));
606 vtkImageData *image =
static_cast<vtkImageData *
>(actor->
image());
613 vtkImageAccumulate *histogram = vtkImageAccumulate::New();
614 histogram->SetComponentExtent(this->
bin_min, this->
bin_max, 0, 0, 0, 0);
615 #if (VTK_MAJOR_VERSION <= 5)
616 histogram->SetInput(image);
618 histogram->SetInputData(image);
620 histogram->SetIgnoreZero(
true);
623 this->
bins =
static_cast<int*
>(histogram->GetOutput()->GetScalarPointer());
642 QRectF scene_rect = rect;
648 scene_rect.setWidth(rect.width() * this->fct_scl);
654 QGraphicsScene::setSceneRect(scene_rect);
666 min->setPos(min->scenePos().x(), rect.height()/2.0);
671 mid->setPos(mid->scenePos().x(), rect.height()/2.0);
676 max->setPos(max->scenePos().x(), rect.height()/2.0);
698 this->fct_scl = 1 / this->fct_scl;
702 vertex->setPos(vertex->pos().x()*this->fct_scl, vertex->pos().y());
707 QGraphicsScene::drawBackground(painter, rect);
715 painter->setPen(QColor(0x35, 0x35, 0x35));
717 painter->setPen(Qt::NoPen);
719 painter->setBrush(QColor(0x77, 0x77, 0xf7));
721 for(
int i = h_x; i < h_x+h_w; i++) {
724 painter->drawRect(QRectF(b_l, t_r));
730 QGraphicsItem *item = this->items(event->scenePos()).first();
732 if(item && dynamic_cast<axlVolumeDiscreteEditorVertex *>(item)) {
733 QGraphicsScene::mouseDoubleClickEvent(event);
738 vertex->setPos(event->scenePos());
739 vertex->setSelected(
true);
752 this->setAttribute(Qt::WA_MacShowFocusRect,
false);
753 this->setCursor(Qt::CrossCursor);
754 this->setFrameShape(QFrame::NoFrame);
755 this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
756 this->setMouseTracking(
true);
757 this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
758 this->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
760 this->setMinimumHeight(300);
770 QGraphicsView::setScene(scene);
777 QGraphicsView::mouseMoveEvent(event);
781 QString x = QString::number(point.x(),
'f', 2);
782 QString y = QString::number(point.y(),
'f', 2);
784 this->setToolTip(QString(
"(%1, %2)").arg(x).arg(y));
789 QGraphicsView::resize(size);
792 this->
scene->update();
797 QGraphicsView::resizeEvent(event);
814 d->volume_view->setScene(d->volume_scene);
815 d->volume_view->setAlignment(Qt::AlignLeft | Qt::AlignBottom);
817 d->dim_x =
new QLineEdit(
this);
818 d->dim_x->setReadOnly(
true);
820 d->dim_y =
new QLineEdit(
this);
821 d->dim_y->setReadOnly(
true);
823 d->dim_z =
new QLineEdit(
this);
824 d->dim_z->setReadOnly(
true);
826 d->sca_min =
new QLineEdit(
this);
827 d->sca_min->setReadOnly(
true);
829 d->sca_max =
new QLineEdit(
this);
830 d->sca_max->setReadOnly(
true);
832 d->log_radio =
new QRadioButton(
this);
833 d->log_radio->setAutoExclusive(
false);
834 d->log_radio->setChecked(
true);
836 d->scl_radio =
new QRadioButton(
this);
837 d->scl_radio->setAutoExclusive(
false);
838 d->scl_radio->setChecked(
false);
840 d->shd_radio =
new QRadioButton(
this);
841 d->shd_radio->setAutoExclusive(
false);
842 d->shd_radio->setChecked(
false);
844 QPushButton *outline_none =
new QPushButton(
"None",
this);
845 outline_none->setCheckable(
true);
846 outline_none->setChecked(
true);
847 outline_none->setObjectName(
"left");
849 QPushButton *outline_corners =
new QPushButton(
"Corners",
this);
850 outline_corners->setCheckable(
true);
851 outline_corners->setChecked(
false);
852 outline_corners->setObjectName(
"middle");
854 QPushButton *outline_box =
new QPushButton(
"Box",
this);
855 outline_box->setCheckable(
true);
856 outline_box->setChecked(
false);
857 outline_box->setObjectName(
"middle");
859 QPushButton *outline_contour =
new QPushButton(
"Contour",
this);
860 outline_contour->setCheckable(
true);
861 outline_contour->setChecked(
false);
862 outline_contour->setObjectName(
"right");
864 QButtonGroup *outline_group =
new QButtonGroup(
this);
865 outline_group->addButton(outline_none);
866 outline_group->addButton(outline_corners);
867 outline_group->addButton(outline_box);
868 outline_group->addButton(outline_contour);
870 QHBoxLayout *outline_layout =
new QHBoxLayout;
871 outline_layout->setSpacing(0);
872 outline_layout->addWidget(outline_none);
873 outline_layout->addWidget(outline_corners);
874 outline_layout->addWidget(outline_box);
875 outline_layout->addWidget(outline_contour);
877 QHBoxLayout *dim_l =
new QHBoxLayout;
878 dim_l->addWidget(d->dim_x);
879 dim_l->addWidget(d->dim_y);
880 dim_l->addWidget(d->dim_z);
882 QHBoxLayout *sca_l =
new QHBoxLayout;
883 sca_l->addWidget(d->sca_min);
884 sca_l->addWidget(d->sca_max);
886 QFormLayout *b_layout =
new QFormLayout;
887 b_layout->setContentsMargins(10, 10, 10, 10);
888 b_layout->setSpacing(10);
889 b_layout->addRow(
"Dimensions", dim_l);
890 b_layout->addRow(
"Scalar range", sca_l);
891 b_layout->addRow(
"Logarithmic count", d->log_radio);
892 b_layout->addRow(
"Scaled values", d->scl_radio);
893 b_layout->addRow(
"Shaded rendering", d->shd_radio);
895 QVBoxLayout *layout =
new QVBoxLayout(
this);
896 layout->setContentsMargins(0, 0, 0, 0);
897 layout->setSpacing(0);
898 layout->addWidget(d->volume_view);
900 layout->addLayout(b_layout);
901 layout->addLayout(outline_layout);
903 connect(d->log_radio, SIGNAL(toggled(
bool)),
this, SLOT(
onLogChecked(
bool)));
904 connect(d->scl_radio, SIGNAL(toggled(
bool)),
this, SLOT(
onSclChecked(
bool)));
905 connect(d->shd_radio, SIGNAL(toggled(
bool)),
this, SLOT(
onShdChecked(
bool)));
907 connect(outline_none, SIGNAL(clicked()),
this, SLOT(
outlineNone()));
908 connect(outline_corners, SIGNAL(clicked()),
this, SLOT(
outlineCorners()));
909 connect(outline_box, SIGNAL(clicked()),
this, SLOT(
outlineBox()));
910 connect(outline_contour, SIGNAL(clicked()),
this, SLOT(
outlineContour()));
933 if(!(d->volume = dynamic_cast<axlVolumeDiscrete *>(volume)))
936 d->dim_x->setText(QString::number(d->volume->xDimension()));
937 d->dim_y->setText(QString::number(d->volume->yDimension()));
938 d->dim_z->setText(QString::number(d->volume->zDimension()));
941 qDebug() << Q_FUNC_INFO <<
"no view selected";
943 if(!d->view->actor(d->volume)){
944 qDebug() << Q_FUNC_INFO <<
"no actor found";
949 d->volume_scene->setActor(actor);
951 d->sca_min->setText(QString::number(d->volume_scene->bin_min));
952 d->sca_max->setText(QString::number(d->volume_scene->bin_max));
958 d->volume_scene->table->view = view;
963 d->volume_scene->setUseLog(checked);
964 d->volume_scene->mapper->use_log = checked;
965 d->volume_scene->update();
970 d->volume_scene->setUseScl(checked);
971 d->volume_view->resize(d->volume_view->size());
972 d->volume_scene->table->update();
973 d->volume_scene->update();
983 vtkVolumeProperty *
property =
static_cast<vtkVolumeProperty *
>(actor->
volumeProperty());
984 property->SetShade(checked);
985 property->Modified();
987 vtkVolume *volume =
static_cast<vtkVolume *
>(actor->
vol());
bool registerInspectorObject(const QString &interface_name, axlInspectorObjectCreator func)
dtkAbstractData * data(void)
void outlineCorners(void)
void outlineContour(void)
void * volumeProperty(void)
axlInspectorObjectInterface * createaxlVolumeDiscreteEditor(void)
QList< axlVolumeDiscreteEditorVertex * > vertices
QPointF mapFromHistgToScene(const QPointF &point)
void setHistgRect(const QRectF &rect)
void onSclChecked(bool checked)
~axlVolumeDiscreteEditorView(void)
void resizeEvent(QResizeEvent *event)
axlVolumeDiscreteEditor(QWidget *parent=0)
void setSceneRect(const QRectF &rect)
void setActor(axlActorVolumeDiscrete *actor)
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
void setVolume(axlAbstractVolumeDiscrete *volume)
~axlVolumeDiscreteEditorTable(void)
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
QPointF axlVolumeDiscreteEditorTableClamp(const QPointF &point, const QRectF &rect)
axlVolumeDiscreteEditorScene * scene
static axlInspectorObjectFactory * instance(void)
void * colorTransferFunction(void)
void onShdChecked(bool checked)
axlVolumeDiscreteEditorView(QWidget *parent=0)
QRectF boundingRect(void) const
virtual void update(void)
void append(axlVolumeDiscreteEditorVertex *vertex)
QPointF mapFromSceneToTable(const QPointF &point)
QPointF mapFromTableToScene(const QPointF &point)
axlVolumeDiscreteEditorTable * table
void resize(const QSize &size)
static bool registered(void)
axlVolumeDiscreteEditorMapper * mapper
axlVolumeDiscreteEditorTable(QGraphicsItem *parent=0)
void mouseMoveEvent(QMouseEvent *event)
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
QRectF boundingRect(void) const
axlVolumeDiscreteEditorVertex(QGraphicsItem *parent=0)
axlActorVolumeDiscrete * actor
void drawBackground(QPainter *painter, const QRectF &rect)
void setScene(axlVolumeDiscreteEditorScene *scene)
~axlVolumeDiscreteEditorScene(void)
void outlineCorners(void)
void outlineContour(void)
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
~axlVolumeDiscreteEditor(void)
~axlVolumeDiscreteEditorVertex(void)
QPointF mapFromSceneToHistg(const QPointF &point)
void onLogChecked(bool checked)
void setView(axlAbstractView *view)
void setSceneRect(const QRectF &rect)
axlVolumeDiscreteEditorMapper * mapper
axlVolumeDiscreteEditorScene(QObject *parent=0)
void * opacityTransferFunction(void)
void setTableRect(const QRectF &rect)