void ColorMap::pointerMotion(Event& event)
	{
	if(isDragging)
		{
		/* Calculate the new value and opacity: */
		GLfloat x1=colorMapAreaBox.getCorner(0)[0];
		GLfloat x2=colorMapAreaBox.getCorner(1)[0];
		GLfloat y1=colorMapAreaBox.getCorner(0)[1];
		GLfloat y2=colorMapAreaBox.getCorner(2)[1];
		Point p=event.getWidgetPoint().getPoint()-dragOffset;
		double newValue=(p[0]-double(x1))*(valueRange.second-valueRange.first)/double(x2-x1)+valueRange.first;
		if(selected==&first)
			newValue=valueRange.first;
		else if(selected==&last)
			newValue=valueRange.second;
		else if(newValue<selected->left->value)
			newValue=selected->left->value;
		else if(newValue>selected->right->value)
			newValue=selected->right->value;
		GLfloat newOpacity=(p[1]-y1)*(1.0f-0.0f)/(y2-y1)+0.0f;
		if(newOpacity<0.0f)
			newOpacity=0.0f;
		else if(newOpacity>1.0f)
			newOpacity=1.0f;
		selected->value=newValue;
		selected->color[3]=newOpacity;
		
		/* Update all control points: */
		updateControlPoints();
		
		/* Call the color map change callbacks: */
		ColorMapChangedCallbackData cbData(this);
		colorMapChangedCallbacks.call(&cbData);
		}
	}
Exemple #2
0
SmartPoly::SmartPoly(vector<ofPoint> pts, float r, ofRectangle b, ofPoint cPos) : SmartShape() {
    // Position is derived from bounding ox center
    pos = b.position + ofPoint(b.width/2,b.height/2);
    capturedPos = cPos;
    
    rotation = r;
    boundingBox = b;
    
    // Setup the poly line
    polyLine = ofPolyline();
    path = ofPath();
    for (vector<ofPoint>::iterator it = pts.begin() ; it != pts.end(); ++it){
        ofPoint p = *it;
        // All points in the poly will be stored respective to pos.
        p = p - pos;
        polyLine.addVertex(p);
        path.lineTo(p);
    }
    polyLine.close();
    path.close();
    
    // Updat the control points
    updateControlPoints();
    
    extrusionHeight = 0;
}
Exemple #3
0
void splineShape::modifyControlPoint(int pointID, displacementStruct displacement)
{
    /*
     * Este metodo pretende implementar un movimiento basico de un punto de control:
     * Argumentos:
     *      - pointID: <unsigned int> identificador del punto sobre el que vamos a operar
     *      - displacement: 
     */

    
    double xdisplacement,ydisplacement;
    
    //Criterio, los puntos de control del borde de ataque y del borde de salida quedan fijos.
    if ( pointID == 0 or pointID == n-1 or pointID == 2*(n-1))//TODO anadir la condicion de pointID == 0
    {
        // There are fixed points.
        xdisplacement = 0.0;
        ydisplacement = 0.0;
    }
    
    else
    {
        xdisplacement = displacement.norm * cos(displacement.theta);
        ydisplacement = displacement.norm * sin(displacement.theta);
    }
    pts[pointID].x += xdisplacement;
    pts[pointID].y += ydisplacement;
    
   calcSplines();
   updateControlPoints();
}
void ColorMap::deleteSelectedControlPoint(void)
	{
	/* Remove the selected control point if possible: */
	if(selected!=0&&selected!=&first&&selected!=&last)
		{
		ControlPoint* delPtr=selected;
		
		{
		/* Unselect the selected control point: */
		SelectedControlPointChangedCallbackData cbData(this,selected,0);
		selected=0;
		selectedControlPointChangedCallbacks.call(&cbData);
		}
		
		/* Remove the control point from the list: */
		delPtr->left->right=delPtr->right;
		delPtr->right->left=delPtr->left;
		delete delPtr;
		
		/* Update all control points: */
		updateControlPoints();
		
		{
		/* Call the color map change callbacks: */
		ColorMapChangedCallbackData cbData(this);
		colorMapChangedCallbacks.call(&cbData);
		}
		}
	}
void ColorMap::insertControlPoint(double newControlPointValue,const ColorMap::ColorMapValue& newControlPointColor)
	{
	/* Insert the new control point if it is inside the value range: */
	if(newControlPointValue>=valueRange.first&&newControlPointValue<=valueRange.second)
		{
		/* Find the two control points on either side of the new control point: */
		ControlPoint* cpPtr1=&first;
		ControlPoint* cpPtr2;
		for(cpPtr2=cpPtr1->right;cpPtr2!=&last&&cpPtr2->value<newControlPointValue;cpPtr1=cpPtr2,cpPtr2=cpPtr2->right)
			;
		
		/* Insert the new control point: */
		ControlPoint* newCp=new ControlPoint(newControlPointValue,newControlPointColor);
		newCp->left=cpPtr1;
		cpPtr1->right=newCp;
		newCp->right=cpPtr2;
		cpPtr2->left=newCp;
		
		/* Update all control points: */
		updateControlPoints();
		
		{
		/* Call the color map change callbacks: */
		ColorMapChangedCallbackData cbData(this);
		colorMapChangedCallbacks.call(&cbData);
		}
		
		{
		/* Select the new control point: */
		SelectedControlPointChangedCallbackData cbData(this,selected,newCp);
		selected=newCp;
		selectedControlPointChangedCallbacks.call(&cbData);
		}
		}
	}
Exemple #6
0
void BSpline::localKnotRefinement(DenseVector x)
{
    // Compute knot insertion matrix
    SparseMatrix A = basis.refineKnotsLocally(x);

    // Update control points
    updateControlPoints(A);
}
Exemple #7
0
void BSpline::insertKnots(double tau, unsigned int dim, unsigned int multiplicity)
{
    // Insert knots and compute knot insertion matrix
    SparseMatrix A = basis.insertKnots(tau, dim, multiplicity);

    // Update control points
    updateControlPoints(A);
}
Exemple #8
0
void BSpline::decomposeToBezierForm()
{
    // Compute knot insertion matrix
    SparseMatrix A = basis.decomposeToBezierForm();

    // Update control points
    updateControlPoints(A);
}
Exemple #9
0
void BSpline::globalKnotRefinement()
{
    // Compute knot insertion matrix
    SparseMatrix A = basis.refineKnots();

    // Update control points
    updateControlPoints(A);
}
void ColorMap::createColorMap(const std::vector<ColorMap::ControlPoint>& controlPoints)
	{
	/* Check if the control point vector is valid: */
	if(controlPoints.size()<2)
		Misc::throwStdErr("ColorMap::createColorMap: control point vector has less than two control points");
	for(std::vector<ColorMap::ControlPoint>::const_iterator cpIt=controlPoints.begin();cpIt!=controlPoints.end();++cpIt)
		{
		std::vector<ColorMap::ControlPoint>::const_iterator cpIt2=cpIt;
		++cpIt2;
		if(cpIt2!=controlPoints.end())
			if(cpIt->value>cpIt2->value)
				Misc::throwStdErr("ColorMap::createColorMap: control point vector has decreasing control point values");
		}
	
	/* Delete the current color map: */
	deleteColorMap();
	
	/* Copy all control points from the control point array: */
	int numPointsSet=0;
	for(std::vector<ColorMap::ControlPoint>::const_iterator cpIt=controlPoints.begin();cpIt!=controlPoints.end();++cpIt)
		{
		if(numPointsSet==0)
			{
			/* Set the first control point: */
			first.value=cpIt->value;
			first.color=cpIt->color;
			}
		else
			{
			if(numPointsSet>1)
				{
				/* Copy the last control point to an intermediate one: */
				ControlPoint* newCp=new ControlPoint(last.value,last.color);
				newCp->left=last.left;
				newCp->left->right=newCp;
				newCp->right=&last;
				last.left=newCp;
				}
			
			/* Set the last control point: */
			last.value=cpIt->value;
			last.color=cpIt->color;
			}
		++numPointsSet;
		}
	
	/* Update the value range: */
	valueRange.first=first.value;
	valueRange.second=last.value;
	
	/* Update all control points: */
	updateControlPoints();
	
	/* Call the color map change callbacks: */
	ColorMapChangedCallbackData cbData(this);
	colorMapChangedCallbacks.call(&cbData);
	}
Exemple #11
0
void ColorMapEditor::
touch()
{
    //update all control points
    updateControlPoints();

    //call the color map change callbacks: */
    ColorMapChangedCallbackData cbData(this);
    colorMapChangedCallbacks.call(&cbData);
}
void ColorMap::resize(const Box& newExterior)
	{
	/* Resize the parent class widget: */
	Widget::resize(newExterior);
	
	/* Adjust the color map area position: */
	colorMapAreaBox=getInterior();
	colorMapAreaBox.doInset(Vector(marginWidth,marginWidth,0.0f));
	
	/* Update the color map area positions of all control points: */
	updateControlPoints();
	}
Exemple #13
0
void ColorMapEditor::
resize(const Box& newExterior)
{
    //resize the parent class widget
    Widget::resize(newExterior);

    //adjust the color map area position
    colorMapAreaBox = getInterior();
    colorMapAreaBox.doInset(Vector(marginWidth, marginWidth, 0.0f));

    //update the color map area positions of all control points
    updateControlPoints();
}
Exemple #14
0
bool BSpline::removeUnsupportedBasisFunctions(std::vector<double> &lb, std::vector<double> &ub)
{
    if (lb.size() != numVariables || ub.size() != numVariables)
        throw Exception("BSpline::removeUnsupportedBasisFunctions: Incompatible dimension of domain bounds.");

    SparseMatrix A = basis.reduceSupport(lb, ub);

    if (coefficients.size() != A.rows())
        return false;

    // Remove unsupported control points (basis functions)
    updateControlPoints(A.transpose());

    return true;
}
Exemple #15
0
ColorMapEditor::
ColorMapEditor(const char* name, Container* parent, bool manageChild_) :
    Widget(name, parent, false),
    marginWidth(0.0f), preferredSize(0.0f,0.0f,0.0f),
    controlPointSize(marginWidth*0.5f),
    selectedControlPointColor(1.0f,0.0f,0.0f),
    selected(-1), isDragging(false)
{
    /* Initialize the control points: */
    updateControlPoints();

    /* Manage me: */
    if(manageChild_)
        manageChild();
}
void ColorMap::createColorMap(ColorMap::ColorMapCreationType colorMapType,const ColorMap::ValueRange& newValueRange)
	{
	/* Delete the current color map: */
	deleteColorMap();
	
	/* Update the value range: */
	valueRange=newValueRange;
	
	if(colorMapType==GREYSCALE)
		{
		/* Create a greyscale color map: */
		first.value=valueRange.first;
		first.color=ColorMapValue(0.0f,0.0f,0.0f,0.0f);
		last.value=valueRange.second;
		last.color=ColorMapValue(1.0f,1.0f,1.0f,1.0f);
		}
	else if(colorMapType==LUMINANCE)
		{
		
		}
	else
		{
		/* Create a rainbow color map: */
		first.value=valueRange.first;
		first.color=ColorMapValue(1.0f,0.0f,0.0f,0.0f);
		ControlPoint* cs[6];
		cs[0]=&first;
		cs[1]=new ControlPoint((1.0/5.0)*(valueRange.second-valueRange.first)+valueRange.first,ColorMapValue(1.0f,1.0f,0.0f,1.0f/5.0f));
		cs[2]=new ControlPoint((2.0/5.0)*(valueRange.second-valueRange.first)+valueRange.first,ColorMapValue(0.0f,1.0f,0.0f,2.0f/5.0f));
		cs[3]=new ControlPoint((3.0/5.0)*(valueRange.second-valueRange.first)+valueRange.first,ColorMapValue(0.0f,1.0f,1.0f,3.0f/5.0f));
		cs[4]=new ControlPoint((4.0/5.0)*(valueRange.second-valueRange.first)+valueRange.first,ColorMapValue(0.0f,0.0f,1.0f,4.0f/5.0f));
		cs[5]=&last;
		last.value=valueRange.second;
		last.color=ColorMapValue(1.0f,0.0f,1.0f,1.0f);
		for(int i=0;i<5;++i)
			{
			cs[i+1]->left=cs[i];
			cs[i]->right=cs[i+1];
			}
		}
	
	/* Update all control points: */
	updateControlPoints();
	
	/* Call the color map change callbacks: */
	ColorMapChangedCallbackData cbData(this);
	colorMapChangedCallbacks.call(&cbData);
	}
void ColorMap::setSelectedControlPointColorValue(const ColorMap::ColorMapValue& newControlPointColorValue)
	{
	if(selected!=0)
		{
		/* Set the control point's color value's RGB and alpha components: */
		for(int i=0;i<4;++i)
			selected->color[i]=newControlPointColorValue[i];
		
		/* Update all control points: */
		updateControlPoints();
		
		/* Call the color map change callbacks: */
		ColorMapChangedCallbackData cbData(this);
		colorMapChangedCallbacks.call(&cbData);
		}
	}
Exemple #18
0
void ColorMapEditor::
pointerMotion(Event& event)
{
    if (isDragging)
    {
        //calculate the new value and opacity
        GLfloat x1 = colorMapAreaBox.getCorner(0)[0];
        GLfloat x2 = colorMapAreaBox.getCorner(1)[0];
        GLfloat y1 = colorMapAreaBox.getCorner(0)[1];
        GLfloat y2 = colorMapAreaBox.getCorner(2)[1];

        Point p = event.getWidgetPoint().getPoint() - dragOffset;
        const Misc::ColorMap::ValueRange vr = colorMap.getValueRange();
        double remap = (vr.max-vr.min) / (x2-x1);
        double newValue = vr.min + (p[0] - double(x1)) * remap;

        //clamp the new value to the valid interval range
        Misc::ColorMap::Points& points = colorMap.getPoints();

        if (selected == 0)
            newValue = vr.min;
        else if(selected == static_cast<int>(controlPoints.size()-1))
            newValue = vr.max;
        else if(newValue < points[selected-1].value)
            newValue = points[selected-1].value;
        else if(newValue > points[selected+1].value)
            newValue = points[selected+1].value;

        //clamp the new opacity to the valid interval
        GLfloat newOpacity = (p[1]-y1) / (y2-y1);
        newOpacity = std::max(newOpacity, 0.0f);
        newOpacity = std::min(newOpacity, 1.0f);

        //assign the new properties
        points[selected].value    = newValue;
        points[selected].color[3] = newOpacity;

        //update all control points
        updateControlPoints();

        //call the color map change callbacks
        ColorMapChangedCallbackData cbData(this);
        colorMapChangedCallbacks.call(&cbData);
    }
}
Exemple #19
0
void splineShape::calcSplines()
{
    /*
     * Este metodo tiene que trabajar sobre los puntos de control que ya existen.
     * Su finalidad es servir como un "update" al calculo de la spline cuando
     * hacemos alguna variacion sobre los puntos de control ya calculados
     */

       int *u;
       bspline(14, t, pts, out_pts);//antes era tpn-1

      //una vez tengo la salida de los puntos del spline quiero sacar los puntos
      //de control marcados para la curva para ver como se comporta a diferentes 
      //grados del polinomio.

      exportControlPoints();
      exportSplines();
      updateControlPoints();
}
void ColorMap::setSelectedControlPointValue(double newControlPointValue)
	{
	if(selected!=0&&selected->left!=0&&selected->right!=0)
		{
		if(newControlPointValue<first.value)
			selected->value=first.value;
		else if(newControlPointValue>last.value)
			selected->value=last.value;
		else
			selected->value=newControlPointValue;
		
		/* Update all control points: */
		updateControlPoints();
		
		/* Call the color map change callbacks: */
		ColorMapChangedCallbackData cbData(this);
		colorMapChangedCallbacks.call(&cbData);
		}
	}
ColorMap::ColorMap(const char* sName,Container* sParent,bool sManageChild)
	:Widget(sName,sParent,false),
	 marginWidth(0.0f),preferredSize(0.0f,0.0f,0.0f),
	 controlPointSize(marginWidth*0.5f),
	 selectedControlPointColor(1.0f,0.0f,0.0f),
	 valueRange(0.0,1.0),
	 first(0.0,ColorMapValue(0.0f,0.0f,0.0f,0.0f)),last(1.0,ColorMapValue(1.0f,1.0f,1.0f,1.0f)),
	 selected(0),isDragging(false)
	{
	/* Link the first and last control points: */
	first.right=&last;
	last.left=&first;
	
	/* Initialize the control points: */
	updateControlPoints();
	
	/* Manage me: */
	if(sManageChild)
		manageChild();
	}
Exemple #22
0
int ColorMapEditor::
insertControlPoint(double value, bool propagate)
{
    //determine the color and entry location
    Misc::ColorMap::Point newPoint(value, Misc::ColorMap::Color());
    Misc::ColorMap::Points::iterator it = colorMap.interpolate(newPoint);

    //insert a new entry into the colormap
    it = colorMap.getPoints().insert(it, newPoint);

    //update all control points
    updateControlPoints(propagate);

    if (propagate)
    {
        //call the color map change callbacks
        ColorMapChangedCallbackData cbData(this);
        colorMapChangedCallbacks.call(&cbData);
    }

    return it - colorMap.getPoints().begin();
}
Exemple #23
0
void GuiWarp::processMouseEvents(const shared_ptr<Warp>& warp, int warpWidth, int warpHeight)
{
    ImGuiIO& io = ImGui::GetIO();

    // Get mouse pos
    ImVec2 mousePos = ImVec2((io.MousePos.x - ImGui::GetCursorScreenPos().x) / warpWidth,
                             -(io.MousePos.y - ImGui::GetCursorScreenPos().y) / warpHeight);

    auto scene = _scene.lock();
    if (!scene)
        return;

    if (io.MouseDownDuration[0] == 0.0)
    {
        // Select a control point
        glm::vec2 picked;
        _currentControlPointIndex = warp->pickControlPoint(glm::vec2(mousePos.x * 2.0 - 1.0, mousePos.y * 2.0 - 1.0), picked);
        scene->sendMessageToWorld("sendAll", {warp->getName(), "showControlPoint", _currentControlPointIndex});
        _previousMousePos = glm::vec2(mousePos.x, mousePos.y);
    }
    else if (io.MouseDownDuration[0] > 0.0)
    {
        Values controlPoints;
        warp->getAttribute("patchControl", controlPoints);
        if (controlPoints.size() < _currentControlPointIndex)
            return;

        Values point = controlPoints[_currentControlPointIndex + 2].asValues();
        glm::vec2 delta = glm::vec2(mousePos.x, mousePos.y) - _previousMousePos;
        _previousMousePos = glm::vec2(mousePos.x, mousePos.y);

        point[0] = point[0].asFloat() + delta.x * 2.0;
        point[1] = point[1].asFloat() + delta.y * 2.0;
        controlPoints[_currentControlPointIndex + 2] = point;

        updateControlPoints(warp->getName(), controlPoints);
    }
}
Exemple #24
0
void ColorMapEditor::
deleteSelectedControlPoint()
{
    if (selected!=-1 && selected!=0 &&
        selected!=static_cast<int>(controlPoints.size()))
    {
        //delete the entry
        Misc::ColorMap::Points& points = colorMap.getPoints();
        points.erase(points.begin()+selected);

        //unselect the control point
        SelectedControlPointChangedCallbackData selectCbData(this,selected,-1);
        selected = -1;
        selectedControlPointChangedCallbacks.call(&selectCbData);

        //update all control points
        updateControlPoints();

        //call the color map change callbacks
        ColorMapChangedCallbackData cbData(this);
        colorMapChangedCallbacks.call(&cbData);
    }
}
void ColorMap::setColorMap(const ColorMap::Storage* newColorMap)
	{
	/* Delete the current color map: */
	deleteColorMap();
	
	/* Set the first control point: */
	first.value=newColorMap->values[0];
	first.color=newColorMap->colors[0];
	
	/* Create and set the intermediate control points: */
	ControlPoint* leftPtr=&first;
	for(int i=1;i<newColorMap->numControlPoints-1;++i)
		{
		ControlPoint* cp=new ControlPoint(newColorMap->values[i],newColorMap->colors[i]);
		cp->left=leftPtr;
		leftPtr->right=cp;
		
		leftPtr=cp;
		}
	
	/* Set the last control point: */
	last.value=newColorMap->values[newColorMap->numControlPoints-1];
	last.color=newColorMap->colors[newColorMap->numControlPoints-1];
	last.left=leftPtr;
	leftPtr->right=&last;
	
	/* Update the value range: */
	valueRange.first=first.value;
	valueRange.second=last.value;
	
	/* Update all control points: */
	updateControlPoints();
	
	/* Call the color map change callbacks: */
	ColorMapChangedCallbackData cbData(this);
	colorMapChangedCallbacks.call(&cbData);
	}
void ColorMap::loadColorMap(const char* colorMapFileName,const ColorMap::ValueRange& newValueRange)
	{
	/* Open the color map file: */
	Misc::File colorMapFile(colorMapFileName,"rt");
	
	/* Delete the current color map: */
	deleteColorMap();
	
	/* Update the value range: */
	valueRange=newValueRange;
	
	/* Read all control points from the color map file: */
	float maxColorComponent=0.0f;
	int numPointsSet=0;
	while(!colorMapFile.eof())
		{
		/* Read the next line from the file: */
		char line[256];
		colorMapFile.gets(line,sizeof(line));
		
		/* Extract the control point from the line (ignore blank and comment lines): */
		double value;
		ColorMapValue color;
		if(line[0]!='#'&&sscanf(line,"%lf %f %f %f %f",&value,&color[0],&color[1],&color[2],&color[3])==5)
			{
			for(int i=0;i<4;++i)
				if(maxColorComponent<color[i])
					maxColorComponent=color[i];
			
			if(numPointsSet==0)
				{
				/* Set the first control point: */
				first.value=value;
				first.color=color;
				}
			else
				{
				if(numPointsSet>1)
					{
					/* Copy the last control point to an intermediate one: */
					ControlPoint* newCp=new ControlPoint(last.value,last.color);
					newCp->left=last.left;
					newCp->left->right=newCp;
					newCp->right=&last;
					last.left=newCp;
					}
				
				/* Set the last control point: */
				last.value=value;
				last.color=color;
				}
			++numPointsSet;
			}
		}
	
	/* Extend the control point list to the new value range: */
	if(first.value>valueRange.first)
		{
		/* Copy the first control point: */
		ControlPoint* newCp=new ControlPoint(first.value,first.color);
		newCp->right=first.right;
		newCp->right->left=newCp;
		newCp->left=&first;
		first.right=newCp;
		
		/* Move the first control point to the left edge of the value range: */
		first.value=valueRange.first;
		}
	if(last.value<valueRange.second)
		{
		/* Copy the last control point: */
		ControlPoint* newCp=new ControlPoint(last.value,last.color);
		newCp->left=last.left;
		newCp->left->right=newCp;
		newCp->right=&last;
		last.left=newCp;
		
		/* Move the last control point to the right edge of the value range: */
		last.value=valueRange.second;
		}
	
	/* Clip the control point list to the new value range: */
	while(first.value<valueRange.first)
		{
		ControlPoint* cp=first.right;
		if(cp->value>valueRange.first)
			{
			/* Interpolate between the first and next control points: */
			double w1=(valueRange.first-first.value)/(cp->value-first.value);
			for(int i=0;i<4;++i)
				first.color[i]=GLfloat(double(first.color[i])*(1.0-w1)+double(cp->color[i])*w1);
			first.value=valueRange.first;
			}
		else
			{
			/* Remove the first control point: */
			first.value=cp->value;
			first.color=cp->color;
			first.right=cp->right;
			cp->right->left=&first;
			delete cp;
			}
		}
	while(last.value>valueRange.second)
		{
		ControlPoint* cp=last.left;
		if(cp->value<valueRange.second)
			{
			/* Interpolate between the last and previous control points: */
			double w1=(valueRange.second-last.value)/(cp->value-last.value);
			for(int i=0;i<4;++i)
				last.color[i]=GLfloat(double(last.color[i])*(1.0-w1)+double(cp->color[i])*w1);
			last.value=valueRange.second;
			}
		else
			{
			/* Remove the last control point: */
			last.value=cp->value;
			last.color=cp->color;
			last.left=cp->left;
			cp->left->right=&last;
			delete cp;
			}
		}
	
	/* Adjust the component range if values were given as unsigned char: */
	if(maxColorComponent>1.0f)
		{
		for(ControlPoint* cp=&first;cp!=0;cp=cp->right)
			for(int i=0;i<4;++i)
				cp->color[i]/=255.0f;
		}
	
	/* Update all control points: */
	updateControlPoints();
	
	/* Call the color map change callbacks: */
	ColorMapChangedCallbackData cbData(this);
	colorMapChangedCallbacks.call(&cbData);
	}
void ColorMap::pointerButtonDown(Event& event)
	{
	/* Find the closest control point to the event's location: */
	GLfloat minDist2=Math::sqr(controlPointSize*1.5f);
	ControlPoint* newSelected=0;
	GLfloat x1=colorMapAreaBox.getCorner(0)[0];
	GLfloat x2=colorMapAreaBox.getCorner(1)[0];
	GLfloat z=colorMapAreaBox.getCorner(0)[2];
	for(ControlPoint* cpPtr=&first;cpPtr!=0;cpPtr=cpPtr->right)
		{
		Point cp(cpPtr->x,cpPtr->y,z);
		GLfloat dist2=Geometry::sqrDist(cp,event.getWidgetPoint().getPoint());
		if(minDist2>dist2)
			{
			minDist2=dist2;
			newSelected=cpPtr;
			for(int i=0;i<2;++i)
				dragOffset[i]=Scalar(event.getWidgetPoint().getPoint()[i]-cp[i]);
			dragOffset[2]=Scalar(0);
			}
		}
	
	/* Create a new control point if none was selected: */
	if(newSelected==0)
		{
		/* Find the two control points on either side of the selected value: */
		double newValue=(event.getWidgetPoint().getPoint()[0]-double(x1))*(valueRange.second-valueRange.first)/double(x2-x1)+valueRange.first;
		if(newValue<valueRange.first)
			newValue=valueRange.first;
		else if(newValue>valueRange.second)
			newValue=valueRange.second;
		ControlPoint* cpPtr1=&first;
		ControlPoint* cpPtr2;
		for(cpPtr2=cpPtr1->right;cpPtr2!=&last&&cpPtr2->value<newValue;cpPtr1=cpPtr2,cpPtr2=cpPtr2->right)
			;
		
		/* Interpolate the new control point: */
		GLfloat w2=GLfloat((newValue-cpPtr1->value)/(cpPtr2->value-cpPtr1->value));
		GLfloat w1=GLfloat((cpPtr2->value-newValue)/(cpPtr2->value-cpPtr1->value));
		ColorMapValue newColorValue;
		for(int i=0;i<4;++i)
			newColorValue[i]=cpPtr1->color[i]*w1+cpPtr2->color[i]*w2;
		
		/* Insert the new control point: */
		ControlPoint* newCp=new ControlPoint(newValue,newColorValue);
		newCp->left=cpPtr1;
		cpPtr1->right=newCp;
		newCp->right=cpPtr2;
		cpPtr2->left=newCp;
		
		/* Update all control points: */
		updateControlPoints();
		
		/* Call the color map change callbacks: */
		ColorMapChangedCallbackData cbData(this);
		colorMapChangedCallbacks.call(&cbData);
		
		/* Select the new control point: */
		newSelected=newCp;
		}
	else if(newSelected==selected)
		{
		/* Start dragging the selected control point: */
		isDragging=true;
		}
	
	/* Call callbacks if selected control point has changed: */
	if(newSelected!=selected)
		{
		SelectedControlPointChangedCallbackData cbData(this,selected,newSelected);
		selected=newSelected;
		selectedControlPointChangedCallbacks.call(&cbData);
		}
	}
Exemple #28
0
void splineShape::initialSpline()
{
      int *u;
      int i;
     
     //____________________________________Creamos el spline para la superficie superior
      
      /*
       * Esta parte se puede emplear para hacer una distribucion senoidal de los puntos
       
      static double step;
      double x;
      int index;
      step = pi/n;
       for (int i = 0; i < n; i++) {//este debe ser n+1
           x = i*step;
           index = (int) ceil( Ni*(0.5*(1-cos(x))) );
            
           if(index == Ni) { index = Ni-1; }
           pts[i].x = xl[index]; pts[i].y=zl[index]; pts[i].z=0.0;
       }


      //_______________________________Generamos los puntos para el spline de la sup. inferior.
      for (int i = 0; i < n; i++) {
          x = i*step;
          index = (int) ceil( Ni*(0.5*(1-cos(x))) );
            
          index = Ni-index;
          if(index == Ni) { index = Ni-1;} //non-"index out of bounds" condition

          //Una vez tenemos calculados los indices creamos los puntos automaticamente
          pts[i+n].x = xu[index];     pts[i+n].y=zu[index];     pts[i+n].z=0.0;
      }
      //_____________________________________________________________________________
    */
      

      //Debido a la distribucion senoidal de los puntos, no se situan donde tenia pensado,
      //tengo que ver como los ajusto...
        pts[0].x = xu[Ni-1];     pts[0].y=zu[Ni-1];    pts[0].z=0.0;
        pts[1].x = xu[84];       pts[1].y=zu[84];      pts[1].z=0.0;
        pts[2].x = xu[70];       pts[2].y=zu[70];      pts[2].z=0.0;
        pts[3].x = xu[49];       pts[3].y=zu[49];      pts[3].z=0.0;
        pts[4].x = xu[30];       pts[4].y=zu[30];      pts[4].z=0.0;
        pts[5].x = xu[16];       pts[5].y=zu[16];      pts[5].z=0.0;
        pts[6].x = xu[3];        pts[6].y=zu[3];       pts[6].z=0.0;
        pts[7].x = xu[0];        pts[7].y=zu[0];       pts[7].z=0.0;
        
        pts[8].x =  xl[3];       pts[8].y=zl[3];       pts[8].z=0.0;
        pts[9].x =  xl[15];      pts[9].y=zl[15];      pts[9].z=0.0;
        pts[10].x = xl[29];      pts[10].y=zl[29];     pts[10].z=0.0;
        pts[11].x = xl[49];      pts[11].y=zl[49];     pts[11].z=0.0;
        pts[12].x = xl[70];      pts[12].y=zl[70];     pts[12].z=0.0;
        pts[13].x = xl[84];      pts[13].y=zl[84];     pts[13].z=0.0;
        pts[14].x = xu[Ni-1];    pts[14].y=zu[Ni-1];   pts[14].z=0.0;

    // Copy pts values to original_pts cause later we will need it.
    for (int i = 0; i < 2*n; i++) {
        original_pts[i].x = pts[i].x; 
        original_pts[i].y = pts[i].y; 
        original_pts[i].z = pts[i].z; 
    }


      out_pts = new point[2*Ni]; //antes teniamos Ni elementos en upper y Ni en lower, ahora debemos tener 2 Ni
      bspline(tnp-1, t, pts, out_pts);
      exportControlPoints();
      updateControlPoints();
}
Exemple #29
0
void GuiWarp::processKeyEvents(const shared_ptr<Warp>& warp)
{
    ImGuiIO& io = ImGui::GetIO();
    // Tabulation key
    if (io.KeysDown[258] && io.KeysDownDuration[258] == 0.0)
    {
        Values controlPoints;
        warp->getAttribute("patchControl", controlPoints);

        if (io.KeyShift)
        {
            _currentControlPointIndex--;
            if (_currentControlPointIndex < 0)
                _currentControlPointIndex = controlPoints.size() - 3;
        }
        else
        {
            _currentControlPointIndex++;
            if (_currentControlPointIndex + 2 >= controlPoints.size())
                _currentControlPointIndex = 0;
        }

        auto scene = _scene.lock();
        scene->sendMessageToWorld("sendAll", {warp->getName(), "showControlPoint", _currentControlPointIndex});
    }
    // Arrow keys
    {
        auto scene = _scene.lock();

        Values controlPoints;
        warp->getAttribute("patchControl", controlPoints);
        if (controlPoints.size() < _currentControlPointIndex + 2)
            return;

        float delta = 0.001f;
        if (io.KeyShift)
            delta = 0.0001f;
        else if (io.KeyCtrl)
            delta = 0.01f;
            
        if (io.KeysDown[262])
        {
            Values point = controlPoints[_currentControlPointIndex + 2].asValues();
            point[0] = point[0].asFloat() + delta;
            controlPoints[_currentControlPointIndex + 2] = point;
            updateControlPoints(warp->getName(), controlPoints);
        }
        if (io.KeysDown[263])
        {
            Values point = controlPoints[_currentControlPointIndex + 2].asValues();
            point[0] = point[0].asFloat() - delta;
            controlPoints[_currentControlPointIndex + 2] = point;
            updateControlPoints(warp->getName(), controlPoints);
        }
        if (io.KeysDown[264])
        {
            Values point = controlPoints[_currentControlPointIndex + 2].asValues();
            point[1] = point[1].asFloat() - delta;
            controlPoints[_currentControlPointIndex + 2] = point;
            updateControlPoints(warp->getName(), controlPoints);
        }
        if (io.KeysDown[265])
        {
            Values point = controlPoints[_currentControlPointIndex + 2].asValues();
            point[1] = point[1].asFloat() + delta;
            controlPoints[_currentControlPointIndex + 2] = point;
            updateControlPoints(warp->getName(), controlPoints);
        }

        return;
    }
}