void MyRendererTFEditor_TFE::initialize( void )
{
    // first clear the markers so this function can be called again to reset
    m_tfe_markers.markers.clear();

	// initialize start and end tf markers
	m_tfe_markers.initMarker(
		0.00, QColor( 0, 0, 0, 0 ), QColor( 0, 0, 0, 0 ) );
	m_tfe_markers.initMarker(	
		1.00, QColor( 0, 0, 0, 0 ), QColor( 0, 0, 0, 0 ) );

	// add default markers
	m_tfe_markers.addMarker(		
		0.30, QColor( 255,  51,  51,  80 ), QColor( 255,  51,  51,  80 ) );
	m_tfe_markers.addMarker(		
		0.50, QColor( 255, 255, 128, 128 ), QColor( 255, 255, 128, 128 ) );
	m_tfe_markers.addMarker(		
		0.95, QColor( 255, 255, 255, 255 ), QColor( 255, 255, 255, 255 ) );

	// add iso markers
	m_tfe_markers.addMarker(		
		0.15, QColor( 228, 209, 192,  75 ), QColor( 228, 209, 192,  75 ), true, 0 );

    if (NUM_VOLUMES > 1)
	m_tfe_markers.addMarker(		
		0.20, QColor( 228, 209, 192,  75 ), QColor( 228, 209, 192,  75 ), true, 1 );

	// initialize utility variables
	m_tfe_marker_selected = 0;
	m_tfe_marker_side = 0;

	updateIsosurface();
	updateTF();
	update();
}
void TransFuncIntensityGradientPainter::mouseMoveEvent(tgt::MouseEvent* event) {
    event->accept();
    tgt::ivec2 size = getCanvas()->getSize();
    tgt::vec2 pos = tgt::vec2(    static_cast<float>(event->x()) / size.x,
                              1.f-static_cast<float>(event->y()) / size.y);

    tgt::vec2 offset = pos - mouseCoord_;

    if (selectedPrimitive_) {
        if (!dragging_) {
            emit toggleInteractionMode(true);
            dragging_ = true;
        }
        // test whether the movement is correct
        /*bool inside = */selectedPrimitive_->move(offset);
        // one or more control points are moved outside of the canvas
        // -> do not allow movement and reset mouse cursor to position before movement
        //if (!inside) {
            //tgt::QtCanvas* canvas = static_cast<tgt::QtCanvas*>(getCanvas());
            //QPoint p(static_cast<int>(mouseCoord_.x * size.x),
                     //static_cast<int>((1.f - mouseCoord_.y) * size.y));
            //p = canvas->mapToGlobal(p);
            //QCursor::setPos(p);
        //}
        //else {
            mouseCoord_ = pos;
            updateTF();
        //}
    }

    getCanvas()->update();
}
void TransFuncIntensityGradientPainter::resetTransferFunction() {
    selectedPrimitive_ = 0;
    tf_->clear();

    updateTF();

    getCanvas()->update();
}
void TransFuncIntensityGradientPainter::fuzzinessChanged(int fuzzi) {
    if (selectedPrimitive_)
        selectedPrimitive_->setFuzziness(fuzzi/100.f);

    updateTF();

    getCanvas()->update();
}
void TransFuncIntensityGradientPainter::setTransFunc(TransFuncIntensityGradient* tf) {
    selectedPrimitive_ = 0;
    tf_ = tf;

    if (tf_) {
        updateTF();
        getCanvas()->update();
    }
}
void TransFuncIntensityGradientPainter::deletePrimitive() {
    if (selectedPrimitive_) {
        tf_->removePrimitive(selectedPrimitive_);
        selectedPrimitive_ = 0;
        updateTF();
        emit primitiveDeselected();

        getCanvas()->update();
    }
}
void TransFuncIntensityGradientPainter::transparencyChanged(int trans) {
    if (selectedPrimitive_) {
        tgt::col4 color = selectedPrimitive_->getColor();
        color.a = trans;
        selectedPrimitive_->setColor(color);
    }

    updateTF();

    getCanvas()->update();
}
void TransFuncIntensityGradientPainter::setHistogramVisible(bool v) {
    showHistogram_ = v;
    if (showHistogram_ && !histogram_) {
        QApplication::setOverrideCursor(Qt::WaitCursor);
        createHistogram();
        createHistogramTexture();
        QApplication::restoreOverrideCursor();

        // update texture of transfer function because the scaling factor changed
        updateTF();
    }
}
void MyRendererTFEditor_TFE::wheelEvent(QWheelEvent *event)
{
	float delta = event->delta() * ( m_display_max - m_display_min ) * 0.000005;

	for( int i = 1; i < m_tfe_markers.markers.size() - 1; i++ )
		if( m_tfe_markers.markers.at( i ).x + delta > 0.0 &&
			m_tfe_markers.markers.at( i ).x + delta < 1.0 )
				m_tfe_markers.markers.at( i ).x += delta;
		 
	update();
	updateIsosurface();
	updateTF();
}
void MyRendererTFEditor_TFE::readMarkers(QDataStream &stream)
{
    // re-initialize utility variables
    m_tfe_marker_selected = 0;
    m_tfe_marker_side = 0;

    // read the marker set from the data stream
    stream >> m_tfe_markers;

    // update everything and emit changed signals
    updateIsosurface();
    updateTF();
    update();
}
void TransFuncIntensityGradientPainter::addQuadPrimitive() {
    // create new primitive
    TransFuncPrimitive* p = new TransFuncQuad(tgt::vec2(0.5f), 0.2f, tgt::col4(128), scaleFactor_);

    // add primitive to transfer function
    tf_->addPrimitive(p);

    // update texture of transfer function
    updateTF();

    // select primitive and update widgets
    selectPrimitive(p);

    // repaint canvas
    getCanvas()->update();
}
Exemplo n.º 12
0
    /** * @brief Render the mesh given a camera and light, using a Phong shader
     * @param mesh Given mesh
     * @param camera Given camera
     * @param lightTrackball Given light camera
     */
    void render (Tucano::Mesh& mesh, const Tucano::Camera& camera, const Tucano::Camera& lightTrackball)
    {

        if (read_va == NULL)
        {
            read_va = mesh.getAttribute("positions1");
            write_va = mesh.getAttribute("positions2");
        }

        if (read_va == NULL || write_va == NULL)
            qDebug() << "AHHH morri";

        updateTF(mesh, camera, lightTrackball);
        Eigen::Vector4f viewport = camera.getViewport();
        glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
        simple.bind();
        // sets all uniform variables for the phong shader

        simple.setUniform("projectionMatrix", camera.getProjectionMatrix());
        simple.setUniform("modelMatrix", mesh.getModelMatrix());
        simple.setUniform("viewMatrix", camera.getViewMatrix());

        glEnable(GL_DEPTH_TEST);
        //mesh.setAttributeLocation(simple);
        mesh.bindBuffers();
//            mesh.resetLocations();
        //qDebug() << mesh.getAttribute("nPos")->getLocation();
        read_va->disable();
        write_va->enable(simple.getAttributeLocation("inPos"));


        mesh.setAttributeLocation("nColor",  simple.getAttributeLocation("inColor"));

        mesh.renderPoints();
        mesh.unbindBuffers();

        simple.unbind();

        VertexAttribute *tmp_va;
        tmp_va = read_va;
        read_va = write_va;
        write_va = tmp_va;
    }
void ViewSphereRender::animate()
{
	if (m_targetPos != NULL)
	{
		if (m_recorder->hasNext())
		{
			const ViewPoint* next = m_recorder->next();//nextPointNearest(m_currentPos, m_targetPos);
			if (next != NULL)
			{
				m_camera.lookAt(next->theta, next->phi);
				//////////////////////////////////////////////////////////////////////////
				updateTF();
				//////////////////////////////////////////////////////////////////////////
			}
		}
		else
		{
			m_timer->stop();
		}
		notifyUpdate();
	}
}
void TransFuncIntensityGradientPainter::colorizePrimitive() {
    if (selectedPrimitive_) {
        tgt::col4 primitiveColor = selectedPrimitive_->getColor();
        // set start color to current color of the primitive
        QColor qcolor(primitiveColor.r, primitiveColor.g, primitiveColor.b, primitiveColor.a);
        qcolor = QColorDialog::getRgba(qcolor.rgba());
        if (qcolor.isValid()) {
            primitiveColor.r = qcolor.red();
            primitiveColor.g = qcolor.green();
            primitiveColor.b = qcolor.blue();
            primitiveColor.a = qcolor.alpha();
            selectedPrimitive_->setColor(primitiveColor);

            // set transparency slider to choosen value
            emit setTransparencySlider(qcolor.alpha());

            updateTF();

            getCanvas()->update();
        }
    }
}
void MyRendererTFEditor_TFE::mouseMoveEvent( QMouseEvent * event )
{
	// if there is a valid node to select
	if( m_mouse_button == Qt::LeftButton && m_tfe_markers.markers.size() > 2 )
	{
		QPoint pos = event->pos();
		QSize size = this->size();

		float x_rescaled = 
			rescale( 0.0, 1.0, pos.x() / float(size.width()), m_display_min, m_display_max );
		float y_rescaled = 
			cml::clamp( 1.0 - pos.y() / float(size.height()), 0.0, 1.0 );

		// new variable names for code clarity
		TFEMarkers * m = & m_tfe_markers;
		int sel = m_tfe_marker_selected;

		// update marker position
		if( m->at( sel )->b_iso || m->at( sel )->color_left == m->at( sel )->color_right )
		{
			m->at( sel )->color_left.setAlphaF( y_rescaled );
			m->at( sel )->color_right.setAlphaF( y_rescaled );
		}
		else 
		{
			if( m_tfe_marker_side < 0 ) m->at( sel )->color_left.setAlphaF( y_rescaled );
			if( m_tfe_marker_side > 0 ) m->at( sel )->color_right.setAlphaF( y_rescaled );
		}
		 m->at( sel )->x = cml::clamp( x_rescaled, 0.0f, 1.0f );

		// re-add marker if ranking has changed
		if(  m->at( sel )->x >  m->at( sel + 1 )->x )
		{
			int count = 1;
			for( int i = sel + 2; i < m->markers.size(); i++ )
				if(  m->at( sel )->x >  m->at( i )->x ) count++;
			
			TFEMarker m_temp =  * m->at( sel );
			m->delMarker( sel );
			m->addMarker( m_temp.x, m_temp.color_left, m_temp.color_right, m_temp.b_iso, m_temp.iso_index );
			sel += count;
		}
		if( m->at( sel )->x < m->at( sel - 1 )->x )
		{
			int count = 1;
			for( int i = sel - 2; i > 0; i-- )
				if( m->at( sel )->x < m->at( i )->x ) count++;
			
			TFEMarker m_temp = * m->at( sel );
			m->delMarker( sel );
			m->addMarker( m_temp.x, m_temp.color_left, m_temp.color_right, m_temp.b_iso, m_temp.iso_index );
			sel -= count;
		}

		m_tfe_marker_selected = sel;
		if( m->at( sel )->b_iso ) updateIsosurface();
		else					  updateTF();

		update();
	}
}
void MyRendererTFEditor_TFE::mouseReleaseEvent( QMouseEvent * event )
{
	// store position and size of widget
	QPoint pos = event->pos();
	int w = this->size().width();
	int h = this->size().height();

	// rescale position coordinates
	float x_rescaled = 
		rescale( 0.0, 1.0, pos.x() / float(w), m_display_min, m_display_max );
	float y_rescaled = 
		1.0 - pos.y() / float(h);

	// new variable names for code clarity
	TFEMarkers * m = & m_tfe_markers;
	int sel = m_tfe_marker_selected;

	// define boundary for pulling markers off the tranfer function graph
	float outside = 0.25;

	// store number of valid colors stored
	int valid_colors;
	if( m_color_selected[1].rgb() != QColor( 0, 0, 0, 0 ).rgb() )		valid_colors = 2;
	else if( m_color_selected[0].rgb() != QColor( 0, 0, 0, 0 ).rgb() )	valid_colors = 1;
	else																valid_colors = 0;

	// if a marker has been dragged off the graph, delete it
	if( ( m_mouse_button == Qt::LeftButton && !m->at( sel )->b_iso ) &&
		( x_rescaled < 0.0 - outside || 
		  x_rescaled > 1.0 + outside || 
		  y_rescaled < 0.0 - outside || 
		  y_rescaled > 1.0 + outside ) )
		m->delMarker( sel );

	// if the user right-clicked and there are valid colors
	else if( m_mouse_button == Qt::RightButton && valid_colors > 0 && 
		( x_rescaled > 0.0 || 
		  x_rescaled < 1.0 || 
		  y_rescaled > 0.0 || 
		  y_rescaled < 1.0 ) )
	{	
		y_rescaled = cml::clamp( y_rescaled, 0.f, 1.f );
		
		m_color_selected[0].setAlphaF( y_rescaled - 0.05 );

		if( valid_colors > 1 ) m_color_selected[1].setAlphaF( y_rescaled + 0.05 );		
		
		// look-up index of adjacent marker
		int adjacent; float low_dist = w;
		for( int i = 1; i < m->markers.size() - 1; i++ )
		{
			// calculate distance to marker
			float x_pos_rescaled = rescale( m_display_min, m_display_max, m->at( i )->x, 0.0, 1.0 );
			float d_x	= ( pos.x() - x_pos_rescaled * w ) ;
			float d_y	= h - pos.y() - h * m->at( i )->color_left.alphaF();
			float dist	= sqrt( d_x * d_x + d_y * d_y );
		
			// if a closer marker is found, pick it
			if( dist < low_dist ) 
			{
				adjacent = i;
				low_dist = dist;
			}
		}

		// if user clicked close to a marker, change it's color
		if( low_dist < 8 )
		{
			if( m->at( adjacent )->b_iso )
			{
				m->at( adjacent )->color_left = m_color_selected[0];
				m->at( adjacent )->color_right = m_color_selected[0];
			}
			else
			{
				if( valid_colors > 1 )
				{
					m->at( adjacent )->color_left = m_color_selected[0];
					m->at( adjacent )->color_right = m_color_selected[1];
				}
				else
				{
					m->at( adjacent )->color_left = m_color_selected[0];
					m->at( adjacent )->color_right = m_color_selected[0];
				}
			}
		}

		// otherwise, if two colors are selected, add a dual color marker
		else if( valid_colors == 2 )
		{
			m_color_selected[0].setAlphaF( y_rescaled - 0.05 );
			m_color_selected[1].setAlphaF( y_rescaled + 0.05 );		
			m->addMarker( x_rescaled, m_color_selected[0], m_color_selected[1], false );
		}

		// otherwise, just add a single color marker
		else
			m->addMarker( x_rescaled, m_color_selected[0], m_color_selected[0], false );
	}

	m_mouse_button = Qt::NoButton;
	m_tfe_marker_selected = 0;
	m_tfe_marker_side = 0;
	update();
	updateIsosurface();
	updateTF();
}