Exemplo n.º 1
0
void TexturedFeather::sampleColor(float lod)
{
	m_stripe->create(resShaft() * m_vane[0].gridU() * 2 + 1, resBarb() + 1);
	unsigned nu, nv;
	computeLODGrid(lod, nu, nv);
	stripe()->begin();
	
	sampleColor(nu, nv, 0);
	sampleColor(nu, nv, 1);
}
Exemplo n.º 2
0
void QgsColorButton::mouseMoveEvent( QMouseEvent *e )
{
  if ( mPickingColor )
  {
    setButtonBackground( sampleColor( e->globalPos() ) );
    e->accept();
    return;
  }

  //handle dragging colors from button
  QColor c = linkedProjectColor();
  if ( !c.isValid() )
    c = mColor;

  if ( !( e->buttons() & Qt::LeftButton ) || !c.isValid() )
  {
    //left button not depressed or no color set, so not a drag
    QToolButton::mouseMoveEvent( e );
    return;
  }

  if ( ( e->pos() - mDragStartPosition ).manhattanLength() < QApplication::startDragDistance() )
  {
    //mouse not moved, so not a drag
    QToolButton::mouseMoveEvent( e );
    return;
  }

  //user is dragging color
  QDrag *drag = new QDrag( this );
  drag->setMimeData( QgsSymbolLayerUtils::colorToMimeData( c ) );
  drag->setPixmap( QgsColorWidget::createDragIcon( c ) );
  drag->exec( Qt::CopyAction );
  setDown( false );
}
Exemplo n.º 3
0
void QgsCompoundColorWidget::mouseMoveEvent( QMouseEvent *e )
{
  if ( mPickingColor )
  {
    //currently in color picker mode
    //sample color under cursor update preview widget to give feedback to user
    QColor hoverColor = sampleColor( e->globalPos() );
    mSamplePreview->setColor( hoverColor );

    e->accept();
    return;
  }

  QWidget::mouseMoveEvent( e );
}
Exemplo n.º 4
0
void QgsColorButton::stopPicking( QPoint eventPos, bool samplingColor )
{
  //release mouse and keyboard, and reset cursor
  releaseMouse();
  releaseKeyboard();
  QgsApplication::restoreOverrideCursor();
  setMouseTracking( false );
  mPickingColor = false;

  if ( !samplingColor )
  {
    //not sampling color, restore old color
    setButtonBackground();
    return;
  }

  setColor( sampleColor( eventPos ) );
  addRecentColor( mColor );
}
Exemplo n.º 5
0
void QgsCompoundColorWidget::stopPicking( QPoint eventPos, const bool takeSample )
{
  //release mouse and keyboard, and reset cursor
  releaseMouse();
  releaseKeyboard();
  unsetCursor();
  setMouseTracking( false );
  mPickingColor = false;

  if ( !takeSample )
  {
    //not sampling color, nothing more to do
    return;
  }

  //grab snapshot of pixel under mouse cursor
  QColor snappedColor = sampleColor( eventPos );
  mSamplePreview->setColor( snappedColor );
  mColorPreview->setColor( snappedColor, true );
}
Exemplo n.º 6
0
//--------------------------------------------------------------
void testApp::update(){
	//grab a new frame
	vidGrabber.grabFrame();
	
	//update the mesh if we have a new frame
	if (vidGrabber.isFrameNew()){
		//this determines how far we extrude the mesh
		for (int i=0; i<vidGrabber.getWidth()*vidGrabber.getHeight(); i++){

			ofFloatColor sampleColor(vidGrabber.getPixels()[i*3]/255.f,				// r
									 vidGrabber.getPixels()[i*3+1]/255.f,			// g
									 vidGrabber.getPixels()[i*3+2]/255.f);			// b
			
			//now we get the vertex aat this position
			//we extrude the mesh based on it's brightness
			ofVec3f tmpVec = mainMesh.getVertex(i);
			tmpVec.z = sampleColor.getBrightness() * extrusionAmount;
			mainMesh.setVertex(i, tmpVec);

			mainMesh.setColor(i, sampleColor);
		}
	}
}
Exemplo n.º 7
0
//--------------------------------------------------------------
void testApp::update(){
	//grab a new frame
	vidGrabber.update();
	
	//update the mesh if we have a new frame
	if (vidGrabber.isFrameNew()){
		//this determines how far we extrude the mesh
		for (int i=0; i<vidGrabber.getWidth()*vidGrabber.getHeight(); i++){

			ofFloatColor sampleColor(vidGrabber.getPixels()[i*3]/255.f,				// r
									 vidGrabber.getPixels()[i*3+1]/255.f,			// g
									 vidGrabber.getPixels()[i*3+2]/255.f);			// b
			
			//now we get the vertex aat this position
			//we extrude the mesh based on it's brightness
			ofVec3f tmpVec = mainMesh.getVertex(i);
			tmpVec.z = sampleColor.getBrightness() * extrusionAmount;
			mainMesh.setVertex(i, tmpVec);

			mainMesh.setColor(i, sampleColor);
		}
	}
	
	//let's move the camera when you move the mouse
	float rotateAmount = ofMap(ofGetMouseY(), 0, ofGetHeight(), 0, 360);

	
	//move the camera around the mesh
	ofVec3f camDirection(0,0,1);
	ofVec3f centre(vidGrabber.getWidth()/2.f,vidGrabber.getHeight()/2.f, 255/2.f);
	ofVec3f camDirectionRotated = camDirection.rotated(rotateAmount, ofVec3f(1,0,0));
	ofVec3f camPosition = centre + camDirectionRotated * extrusionAmount;
	
	cam.setPosition(camPosition);
	cam.lookAt(centre);
}
Exemplo n.º 8
0
//--------------------------------------------------------------
void ofApp::draw() {

	//We are going to start by copying the sphereReference mesh into the deformPlane vboMesh
	deformPlane = sphereReference.getMesh();

	//We want to enable it to show the mesh
	ofEnableDepthTest();

	//We're going to create a 3 dimensional float vector to store each vertex
	ofVec3f vertexValue;

	//Loop goes through all the vertecies we want to transform
	for (int i = 0; i < deformPlane.getNumIndices(); i++) { 

	    //Update gradually
		amp = 0.000001; 

		//Get the current vertex value and store it.
		int vertexIndex = deformPlane.getIndex(i);
		vertexValue = deformPlane.getVertex(vertexIndex); 

		//Enables Pattrent Displacment
		if (pattern) {
			//Displaces vertecies in an even pattern 
			//by only applying to an index divisible by a number you chose
			if ((i & iterations) == 0) { 
				for (int j = 0; j < 10; j++) {
					vertexValue.x *= (extrude + 1);
					vertexValue.y *= (extrude + 1);
					vertexValue.z *= (extrude + 1);
				}
			}
		}

		//Displaces sphere with sinewaves, credit to Mick Grierson and his AV Lab examples
		if (sinusoid) {
			//Determine magnitude and phase based on mouse movement and iteration
			float er = cos(sin(mouseX  * amp*i));
			float ery = cos(cos(mouseY  * amp*i));

			//Apply sine and cos displacment to vertecies
			vertexValue.x *= er; 
			vertexValue.y *= ery;
			//Both sine and cos for distance
			vertexValue.z *= er*ery;
		}

		//Displaces mesh based on its texture map
		if (texture) {	

		    //Maps number of Indicies to number of Pixels
			pointer = ofMap(i, 0, deformPlane.getNumIndices(), 0, scaled.getWidth()*scaled.getHeight());
		
			//Get colour value of pixel
			ofFloatColor sampleColor(scaled.getPixels()[pointer * 3],				// r
			                       	scaled.getPixels()[pointer * 3 + 1],			// g
				                    scaled.getPixels()[pointer * 3 + 2]);			// b

			vertexValue.x *= sampleColor.getBrightness() * extrude + 1;
			vertexValue.y *= sampleColor.getBrightness() * extrude + 1;
			vertexValue.z *= sampleColor.getBrightness() * extrude + 1;
		}

		//Set vertex position
		deformPlane.setVertex(vertexIndex, vertexValue); // write it all back, including the new z.
	}


	cam.begin();
	//Store current position, anything drawn after maintains these coordinates
	sphereReference.transformGL();

	//Map texture coordinates to sphere
	sphereReference.mapTexCoordsFromTexture(img.getTexture());

	//Now we draw and texture bind our newly deformed sphere mesh
	img.getTexture().bind();
	deformPlane.draw();
	img.getTexture().unbind();

	//Restore the coordinate system
	sphereReference.restoreTransformGL();
	cam.end();

	//Disable depth testing to draw image and video
	ofDisableDepthTest();

	gui.draw();
}
Exemplo n.º 9
0
void Plot2DHistogram::drawColumn (QPainter * painter, const QwtColumnRect & rect,
        const QwtIntervalSample & sample) const{
    QBrush brush( m_defaultColor );
    if ( !m_colored ){
        painter->setPen( m_defaultColor);
    }
    else {
        QColor sampleColor(m_defaultColor);
        if ( m_pipeline ){
            QwtInterval xRange = sample.interval;
            double midPt = (xRange.minValue() + xRange.maxValue()) / 2;
            std::array<double,3> normRGB;
            m_pipeline->convert( midPt, normRGB );
            if ( normRGB[0] >= 0 && normRGB[1] >= 0 && normRGB[2] >= 0 ){
                sampleColor.setRgbF(normRGB[0], normRGB[1], normRGB[2]);
            }
        }
        painter->setPen( sampleColor );
        brush.setColor( sampleColor );
    }
    painter->setBrush( brush );
    QRectF r = rect.toRect();
    if ( QwtPainter::roundingAlignment( painter ) ){
        r.setLeft( qRound( r.left() ) );
        r.setRight( qRound( r.right() ) );
        r.setTop( qRound( r.top() ) );
        r.setBottom( qRound( r.bottom() ) );
    }
    if ( m_drawStyle == Carta::Data::PlotStyles::PLOT_STYLE_FILL ){
        QwtPainter::fillRect( painter, r, brush );
    }
    else if ( m_drawStyle == Carta::Data::PlotStyles::PLOT_STYLE_LINE ){
        double middle = ( r.left() + r.right() ) / 2;
        QwtPainter::drawLine( painter, middle, r.bottom(), middle, r.top() );
    }
    else if ( m_drawStyle != Carta::Data::PlotStyles::PLOT_STYLE_OUTLINE ){
            qCritical() << "Unrecognized draw style="<< m_drawStyle;
    }


    if ( m_drawStyle == Carta::Data::PlotStyles::PLOT_STYLE_OUTLINE ||
            ( m_drawStyle == Carta::Data::PlotStyles::PLOT_STYLE_FILL && m_colored ) ){
        //Draw a black outline for colored fill style
        if ( m_drawStyle == Carta::Data::PlotStyles::PLOT_STYLE_FILL && m_colored ){
            QColor outlineC( "black" );
            painter->setPen( outlineC );
        }

        //Draw the top
        double top = r.top();
        double right = r.right();
        QwtPainter::drawLine( painter, r.left(), top, r.right(), top );
        //Draw the left vertical line
        QwtPainter::drawLine( painter, r.left(), m_lastY, r.left(), top );
        //Store the top for the next call.
        if ( top > 0 ){
            m_lastY = top;
        }
        if ( right > 0 ){
            m_lastX = right;
        }
    }
}
Exemplo n.º 10
0
//--------------------------------------------------------------
void ofApp::update() {
    
    float t = (ofGetElapsedTimef()) * 0.9f;
    float div = 250.0;
    
    for (int i=0; i<NUM_BILLBOARDS; i++) {
        
        // noise
        ofVec3f vec(ofSignedNoise(t, billboards.getVertex(i).y/div, billboards.getVertex(i).z/div),
                    ofSignedNoise(billboards.getVertex(i).x/div, t, billboards.getVertex(i).z/div),
                    ofSignedNoise(billboards.getVertex(i).x/div, billboards.getVertex(i).y/div, t));
        
        vec *= 10 * ofGetLastFrameTime();
        billboardVels[i] += vec;
        billboards.getVertices()[i] += billboardVels[i];
        billboardVels[i] *= 0.94f;
        billboards.setNormal(i,ofVec3f(12 + billboardSizeTarget[i] * ofNoise(t+i),0,0));
    }
    
    
    // move the camera around
    float mx = (float)mouseX/(float)ofGetWidth();
    float my = (float)mouseY/(float)ofGetHeight();
    ofVec3f des(mx * 360.0, my * 360.0, 0);
    cameraRotation += (des-cameraRotation) * 0.03;
    zoom += (zoomTarget - zoom) * 0.03;
    
    //grab a new frame
    vidGrabber.update();
    
    //update the mesh if we have a new frame
    if (vidGrabber.isFrameNew()){
        //this determines how far we extrude the mesh
        for (int i=0; i<vidGrabber.getWidth()*vidGrabber.getHeight(); i++){
            
            ofFloatColor sampleColor(vidGrabber.getPixels()[i*3]/255.f,				// r
                                     vidGrabber.getPixels()[i*3+1]/255.f,			// g
                                     vidGrabber.getPixels()[i*3+2]/255.f);			// b
            
            //now we get the vertex aat this position
            //we extrude the mesh based on it's brightness
            ofVec3f tmpVec = mainMesh.getVertex(i);
            tmpVec.z = sampleColor.getBrightness() * extrusionAmount;
            mainMesh.setVertex(i, tmpVec);
            
            mainMesh.setColor(i, sampleColor);
        }
    }
    
    //let's move the camera when you move the mouse
    float rotateAmount = ofMap(ofGetMouseY(), 0, ofGetHeight(), 0, 360);
    
    
    //move the camera around the mesh
    ofVec3f camDirection(0,0,1);
    ofVec3f centre(vidGrabber.getWidth()/2.f,vidGrabber.getHeight()/2.f, 255/2.f);
    ofVec3f camDirectionRotated = camDirection.rotated(rotateAmount, ofVec3f(1,0,0));
    ofVec3f camPosition = centre + camDirectionRotated * extrusionAmount;
    
    cam.setPosition(camPosition);
    cam.lookAt(centre);

    
}