New curve type : "cage control"
This commit is contained in:
@@ -708,3 +708,7 @@ HISTOGRAM_BUTTON_R;R
|
|||||||
HISTOGRAM_BUTTON_G;G
|
HISTOGRAM_BUTTON_G;G
|
||||||
HISTOGRAM_BUTTON_B;B
|
HISTOGRAM_BUTTON_B;B
|
||||||
HISTOGRAM_BUTTON_L;L
|
HISTOGRAM_BUTTON_L;L
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
CURVEEDITOR_NURBS;Control cage
|
||||||
|
@@ -710,3 +710,7 @@ HISTOGRAM_BUTTON_R;R
|
|||||||
HISTOGRAM_BUTTON_G;G
|
HISTOGRAM_BUTTON_G;G
|
||||||
HISTOGRAM_BUTTON_B;B
|
HISTOGRAM_BUTTON_B;B
|
||||||
HISTOGRAM_BUTTON_L;L
|
HISTOGRAM_BUTTON_L;L
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
CURVEEDITOR_NURBS;Control cage
|
||||||
|
@@ -686,3 +686,7 @@ HISTOGRAM_BUTTON_B;B
|
|||||||
HISTOGRAM_BUTTON_L;L
|
HISTOGRAM_BUTTON_L;L
|
||||||
PREFERENCES_DCBENHANCE;Appliquer la phase d'amélioration de DCB
|
PREFERENCES_DCBENHANCE;Appliquer la phase d'amélioration de DCB
|
||||||
PREFERENCES_DCBITERATIONS;Nombre d'itération de DCB
|
PREFERENCES_DCBITERATIONS;Nombre d'itération de DCB
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
CURVEEDITOR_NURBS;Cage de contrôle
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
|
|
||||||
include_directories (${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../rtexif
|
include_directories (${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../rtexif
|
||||||
${EXTRA_INCDIR} ${GTHREAD_INCLUDE_DIRS} ${GOBJECT_INCLUDE_DIRS} ${GLIB2_INCLUDE_DIRS}
|
${EXTRA_INCDIR} ${GTHREAD_INCLUDE_DIRS} ${GOBJECT_INCLUDE_DIRS} ${GLIB2_INCLUDE_DIRS}
|
||||||
${GLIBMM_INCLUDE_DIRS} ${IPTCDATA_INCLUDE_DIRS} ${LCMS_INCLUDE_DIRS})
|
${GLIBMM_INCLUDE_DIRS} ${IPTCDATA_INCLUDE_DIRS} ${LCMS_INCLUDE_DIRS}
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../rtgui ${GTKMM_INCLUDE_DIRS})
|
||||||
link_directories (${CMAKE_CURRENT_SOURCE_DIR}/../rtexif ${EXTRA_LIBDIR} ${GTHREAD_LIBRARY_DIRS}
|
link_directories (${CMAKE_CURRENT_SOURCE_DIR}/../rtexif ${EXTRA_LIBDIR} ${GTHREAD_LIBRARY_DIRS}
|
||||||
${GOBJECT_LIBRARY_DIRS} ${GLIB2_LIBRARY_DIRS} ${GLIBMM_LIBRARY_DIRS}
|
${GOBJECT_LIBRARY_DIRS} ${GLIB2_LIBRARY_DIRS} ${GLIBMM_LIBRARY_DIRS}
|
||||||
${IPTCDATA_LIBRARY_DIRS} ${LCMS_LIBRARY_DIRS})
|
${IPTCDATA_LIBRARY_DIRS} ${LCMS_LIBRARY_DIRS})
|
||||||
|
@@ -30,14 +30,16 @@
|
|||||||
|
|
||||||
namespace rtengine {
|
namespace rtengine {
|
||||||
|
|
||||||
Curve::Curve (const std::vector<double>& p) : x(NULL), y(NULL), ypp(NULL) {
|
Curve::Curve (const std::vector<double>& p, int poly_pn) : x(NULL), y(NULL), ypp(NULL) {
|
||||||
|
|
||||||
|
ppn = poly_pn;
|
||||||
|
|
||||||
if (p.size()<3) {
|
if (p.size()<3) {
|
||||||
kind = 0;
|
kind = Empty;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
kind = p[0];
|
kind = (CurveType)p[0];
|
||||||
if (kind==-1 || kind==1) {
|
if (kind==Linear || kind==Spline || kind==NURBS) {
|
||||||
N = (p.size()-1)/2;
|
N = (p.size()-1)/2;
|
||||||
x = new double[N];
|
x = new double[N];
|
||||||
y = new double[N];
|
y = new double[N];
|
||||||
@@ -46,12 +48,14 @@ Curve::Curve (const std::vector<double>& p) : x(NULL), y(NULL), ypp(NULL) {
|
|||||||
x[i] = p[ix++];
|
x[i] = p[ix++];
|
||||||
y[i] = p[ix++];
|
y[i] = p[ix++];
|
||||||
}
|
}
|
||||||
if (kind==1)
|
if (kind==Spline)
|
||||||
spline_cubic_set ();
|
spline_cubic_set ();
|
||||||
|
else if (kind==NURBS && N > 2)
|
||||||
|
NURBS_set ();
|
||||||
}
|
}
|
||||||
if (kind==2) {
|
else if (kind==Parametric) {
|
||||||
if (p.size()!=8 && p.size()!=9)
|
if (p.size()!=8 && p.size()!=9)
|
||||||
kind = 0;
|
kind = Empty;
|
||||||
else {
|
else {
|
||||||
x = new double[9];
|
x = new double[9];
|
||||||
for (int i=0; i<4; i++)
|
for (int i=0; i<4; i++)
|
||||||
@@ -98,13 +102,99 @@ void Curve::spline_cubic_set () {
|
|||||||
delete [] u;
|
delete [] u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Curve::NURBS_set () {
|
||||||
|
|
||||||
|
std::vector<double> sc_x; // X sub-curve points ( XP0,XP1,XP2, XP2,XP3,XP4, ...)
|
||||||
|
std::vector<double> sc_y; // Y sub-curve points ( YP0,YP1,YP2, YP2,YP3,YP4, ...)
|
||||||
|
std::vector<double> sc_length; // Length of the subcurves
|
||||||
|
double total_length=0;
|
||||||
|
|
||||||
|
// Create the list of Bezier sub-curves
|
||||||
|
// NURBS_set is called if N > 2 only
|
||||||
|
|
||||||
|
for (int i = 0; i < N-1;) {
|
||||||
|
double length;
|
||||||
|
|
||||||
|
// first point (on the curve)
|
||||||
|
double sc_x2, sc_y2;
|
||||||
|
if (!i) {
|
||||||
|
sc_x2 = x[i];
|
||||||
|
sc_y2 = y[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sc_x2 = (x[i-1] + x[i]) / 2.;
|
||||||
|
sc_y2 = (y[i-1] + y[i]) / 2.;
|
||||||
|
}
|
||||||
|
sc_x.push_back(sc_x2);
|
||||||
|
sc_y.push_back(sc_y2);
|
||||||
|
|
||||||
|
// second point (control point)
|
||||||
|
sc_x.push_back(x[i]);
|
||||||
|
sc_y.push_back(y[i]);
|
||||||
|
length = sqrt(pow(x[i] - sc_x2,2) + pow(y[i] - sc_y2,2));
|
||||||
|
i++;
|
||||||
|
|
||||||
|
// third point (on the curve)
|
||||||
|
if (i==N-1) {
|
||||||
|
sc_x2 = x[i];
|
||||||
|
sc_y2 = y[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sc_x2 = (x[i-1] + x[i]) / 2.;
|
||||||
|
sc_y2 = (y[i-1] + y[i]) / 2.;
|
||||||
|
}
|
||||||
|
sc_x.push_back(sc_x2);
|
||||||
|
sc_y.push_back(sc_y2);
|
||||||
|
length += sqrt(pow(x[i] - sc_x2,2) + pow(y[i] - sc_y2,2));
|
||||||
|
|
||||||
|
// Storing the length of all sub-curves and the total length (to have a better distribution
|
||||||
|
// of the points along the curve)
|
||||||
|
sc_length.push_back(length);
|
||||||
|
total_length += length;
|
||||||
|
}
|
||||||
|
sc_x.begin();
|
||||||
|
sc_y.begin();
|
||||||
|
sc_length.begin();
|
||||||
|
|
||||||
|
// create the polyline with the number of points adapted to the X range of the sub-curve
|
||||||
|
for (int i=0; i < sc_x.size(); i+=3) {
|
||||||
|
// TODO: Speeding-up the interface by caching the polyline, instead of rebuilding it at each action on sliders !!!
|
||||||
|
int nbr_points = (int)(((double)ppn+N-2) * sc_length[i/3] / total_length) + (i==0 ? 1 : 0);
|
||||||
|
|
||||||
|
// increment along the curve, not along the X axis
|
||||||
|
double increment = 1.0 / (double)(nbr_points-1);
|
||||||
|
if (!i) {
|
||||||
|
poly_x.push_back(sc_x[i]);
|
||||||
|
poly_y.push_back(sc_y[i]);
|
||||||
|
}
|
||||||
|
for (int j=1; j<nbr_points-1; j++) {
|
||||||
|
double t = j*increment;
|
||||||
|
double t2 = t*t;
|
||||||
|
double tr = 1.-t;
|
||||||
|
double tr2 = tr*tr;
|
||||||
|
double tr2t = tr*2*t;
|
||||||
|
|
||||||
|
// adding a point to the polyline
|
||||||
|
poly_x.push_back( tr2*sc_x[i] + tr2t*sc_x[i+1] + t2*sc_x[i+2] );
|
||||||
|
poly_y.push_back( tr2*sc_y[i] + tr2t*sc_y[i+1] + t2*sc_y[i+2] );
|
||||||
|
}
|
||||||
|
// adding the last point of the sub-curve
|
||||||
|
poly_x.push_back(sc_x[i+2]);
|
||||||
|
poly_y.push_back(sc_y[i+2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
double Curve::getVal (double t) {
|
double Curve::getVal (double t) {
|
||||||
|
|
||||||
if (!kind)
|
switch (kind) {
|
||||||
|
|
||||||
|
case Empty :
|
||||||
return t;
|
return t;
|
||||||
|
break;
|
||||||
|
|
||||||
if (kind==2) {
|
case Parametric : {
|
||||||
|
|
||||||
if (t<=1e-14)
|
if (t<=1e-14)
|
||||||
return 0.0;
|
return 0.0;
|
||||||
double c = -log(2.0)/log(x[2]);
|
double c = -log(2.0)/log(x[2]);
|
||||||
@@ -130,14 +220,17 @@ double Curve::getVal (double t) {
|
|||||||
double hstretched = fc + (1-fc)*(hbase<=1e-14 ? 0.0 : exp(log(hbase)/hc));
|
double hstretched = fc + (1-fc)*(hbase<=1e-14 ? 0.0 : exp(log(hbase)/hc));
|
||||||
return hstretched;
|
return hstretched;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else {
|
case Linear :
|
||||||
|
case Spline : {
|
||||||
|
// values under and over the first and last point
|
||||||
if (t>x[N-1])
|
if (t>x[N-1])
|
||||||
return y[N-1];
|
return y[N-1];
|
||||||
else if (t<x[0])
|
else if (t<x[0])
|
||||||
return y[0];
|
return y[0];
|
||||||
|
|
||||||
/* do a binary search for the right interval: */
|
// do a binary search for the right interval:
|
||||||
int k_lo = 0, k_hi = N - 1;
|
int k_lo = 0, k_hi = N - 1;
|
||||||
while (k_hi - k_lo > 1){
|
while (k_hi - k_lo > 1){
|
||||||
int k = (k_hi + k_lo) / 2;
|
int k = (k_hi + k_lo) / 2;
|
||||||
@@ -148,17 +241,43 @@ double Curve::getVal (double t) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double h = x[k_hi] - x[k_lo];
|
double h = x[k_hi] - x[k_lo];
|
||||||
if (kind==-1)
|
// linear
|
||||||
|
if (kind==Linear)
|
||||||
return y[k_lo] + (t - x[k_lo]) * ( y[k_hi] - y[k_lo] ) / h;
|
return y[k_lo] + (t - x[k_lo]) * ( y[k_hi] - y[k_lo] ) / h;
|
||||||
else if (kind==1) {
|
// spline curve
|
||||||
|
else { // if (kind==Spline) {
|
||||||
double a = (x[k_hi] - t) / h;
|
double a = (x[k_hi] - t) / h;
|
||||||
double b = (t - x[k_lo]) / h;
|
double b = (t - x[k_lo]) / h;
|
||||||
double r = a*y[k_lo] + b*y[k_hi] + ((a*a*a - a)*ypp[k_lo] + (b*b*b - b)*ypp[k_hi]) * (h*h)/6.0;
|
double r = a*y[k_lo] + b*y[k_hi] + ((a*a*a - a)*ypp[k_lo] + (b*b*b - b)*ypp[k_hi]) * (h*h)/6.0;
|
||||||
if (r < 0.0) return 0.0;
|
return CLIPD(r);
|
||||||
if (r > 1.0) return 1.0;
|
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case NURBS : {
|
||||||
|
// values under and over the first and last point
|
||||||
|
if (t>x[N-1])
|
||||||
|
return y[N-1];
|
||||||
|
else if (t<x[0])
|
||||||
|
return y[0];
|
||||||
|
else if (N == 2)
|
||||||
|
return y[0] + (t - x[0]) * ( y[1] - y[0] ) / (x[1] - x[0]);
|
||||||
|
|
||||||
|
// do a binary search for the right interval:
|
||||||
|
int k_lo = 0, k_hi = poly_x.size() - 1;
|
||||||
|
while (k_hi - k_lo > 1){
|
||||||
|
int k = (k_hi + k_lo) / 2;
|
||||||
|
if (poly_x[k] > t)
|
||||||
|
k_hi = k;
|
||||||
else
|
else
|
||||||
|
k_lo = k;
|
||||||
|
}
|
||||||
|
|
||||||
|
double h = poly_x[k_hi] - poly_x[k_lo];
|
||||||
|
return poly_y[k_lo] + (t - poly_x[k_lo]) * ( poly_y[k_hi] - poly_y[k_lo] ) / h;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
// all other (unknown) kind
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -322,7 +441,7 @@ void CurveFactory::complexCurve (double ecomp, double black, double hlcompr, dou
|
|||||||
// create a curve if needed
|
// create a curve if needed
|
||||||
Curve* tcurve = NULL;
|
Curve* tcurve = NULL;
|
||||||
if (curvePoints.size()>0 && curvePoints[0]!=0)
|
if (curvePoints.size()>0 && curvePoints[0]!=0)
|
||||||
tcurve = new Curve (curvePoints);
|
tcurve = new Curve (curvePoints, CURVES_MIN_POLY_POINTS/skip);
|
||||||
|
|
||||||
// clear array that stores histogram valid before applying the custom curve
|
// clear array that stores histogram valid before applying the custom curve
|
||||||
if (outBeforeCCurveHistogram)
|
if (outBeforeCCurveHistogram)
|
||||||
@@ -330,7 +449,7 @@ void CurveFactory::complexCurve (double ecomp, double black, double hlcompr, dou
|
|||||||
|
|
||||||
for (int i=0; i<=0xffff; i+= i<0xffff-skip ? skip : 1 ) {
|
for (int i=0; i<=0xffff; i+= i<0xffff-skip ? skip : 1 ) {
|
||||||
|
|
||||||
// change to [0,1] rage
|
// change to [0,1] range
|
||||||
double val = (double)i / 65535.0;
|
double val = (double)i / 65535.0;
|
||||||
|
|
||||||
// apply default multiplier (that is >1 if highlight recovery is on)
|
// apply default multiplier (that is >1 if highlight recovery is on)
|
||||||
@@ -346,7 +465,7 @@ void CurveFactory::complexCurve (double ecomp, double black, double hlcompr, dou
|
|||||||
// apply brightness curve
|
// apply brightness curve
|
||||||
val = brightness (val, br/100.0);
|
val = brightness (val, br/100.0);
|
||||||
|
|
||||||
// apply custom/parametric curve, if any
|
// apply custom/parametric/NURBS curve, if any
|
||||||
if (tcurve) {
|
if (tcurve) {
|
||||||
if (outBeforeCCurveHistogram) {
|
if (outBeforeCCurveHistogram) {
|
||||||
double hval = val;
|
double hval = val;
|
||||||
|
@@ -23,6 +23,9 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <mycurve.h>
|
||||||
|
|
||||||
|
#define CURVES_MIN_POLY_POINTS 1000
|
||||||
|
|
||||||
namespace rtengine {
|
namespace rtengine {
|
||||||
|
|
||||||
@@ -132,13 +135,17 @@ class Curve {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
int N;
|
int N;
|
||||||
|
int ppn; // targeted polyline point number
|
||||||
double* x;
|
double* x;
|
||||||
double* y;
|
double* y;
|
||||||
|
std::vector<double> poly_x; // X points of the faceted curve
|
||||||
|
std::vector<double> poly_y; // Y points of the faceted curve
|
||||||
double* ypp;
|
double* ypp;
|
||||||
int kind; // = -1: linear interp., 0: empty, 1: spline interp., 2: parametric
|
CurveType kind;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void spline_cubic_set ();
|
void spline_cubic_set ();
|
||||||
|
void NURBS_set ();
|
||||||
static inline double p00 (double x, double prot) { return CurveFactory::clower (x, 2.0, prot); }
|
static inline double p00 (double x, double prot) { return CurveFactory::clower (x, 2.0, prot); }
|
||||||
static inline double p11 (double x, double prot) { return CurveFactory::cupper (x, 2.0, prot); }
|
static inline double p11 (double x, double prot) { return CurveFactory::cupper (x, 2.0, prot); }
|
||||||
static inline double p01 (double x, double prot) { return x<=0.5 ? CurveFactory::clower (x*2, 2.0, prot)/2.0 : 0.5 + CurveFactory::cupper ((x-0.5)*2, 2.0, prot)/2.0; }
|
static inline double p01 (double x, double prot) { return x<=0.5 ? CurveFactory::clower (x*2, 2.0, prot)/2.0 : 0.5 + CurveFactory::cupper ((x-0.5)*2, 2.0, prot)/2.0; }
|
||||||
@@ -147,7 +154,7 @@ class Curve {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Curve (const std::vector<double>& points);
|
Curve (const std::vector<double>& points, int ppn=CURVES_MIN_POLY_POINTS);
|
||||||
~Curve ();
|
~Curve ();
|
||||||
|
|
||||||
double getVal (double x);
|
double getVal (double x);
|
||||||
|
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
extern Glib::ustring argv0;
|
extern Glib::ustring argv0;
|
||||||
|
|
||||||
CurveEditor::CurveEditor () : cl(NULL), activeParamControl(-1), realized(false), curveTypeIx(-1) {
|
CurveEditor::CurveEditor () : cl(NULL), activeParamControl(-1), realized(false), curveTypeIx(Linear) {
|
||||||
|
|
||||||
Gtk::HBox* tsbox = Gtk::manage (new Gtk::HBox ());
|
Gtk::HBox* tsbox = Gtk::manage (new Gtk::HBox ());
|
||||||
Gtk::Label* tslab = Gtk::manage (new Gtk::Label (M("CURVEEDITOR_TYPE")));
|
Gtk::Label* tslab = Gtk::manage (new Gtk::Label (M("CURVEEDITOR_TYPE")));
|
||||||
@@ -41,10 +41,12 @@ CurveEditor::CurveEditor () : cl(NULL), activeParamControl(-1), realized(false),
|
|||||||
|
|
||||||
pack_start (*tsbox);
|
pack_start (*tsbox);
|
||||||
|
|
||||||
curveType->append_text (M("CURVEEDITOR_LINEAR"));
|
// Order set in the same order than "enum CurveType". Shouldn't change, for compatibility reason
|
||||||
curveType->append_text (M("CURVEEDITOR_PARAMETRIC"));
|
curveType->append_text (M("CURVEEDITOR_LINEAR")); // 0 Linear
|
||||||
curveType->append_text (M("CURVEEDITOR_CUSTOM"));
|
curveType->append_text (M("CURVEEDITOR_CUSTOM")); // 1 Spline
|
||||||
curveType->set_active (0);
|
curveType->append_text (M("CURVEEDITOR_PARAMETRIC")); // 2 Parametric
|
||||||
|
curveType->append_text (M("CURVEEDITOR_NURBS")); // 3 NURBS
|
||||||
|
curveType->set_active (Linear);
|
||||||
|
|
||||||
curve_reset->signal_clicked().connect( sigc::mem_fun(*this, &CurveEditor::curveResetPressed) );
|
curve_reset->signal_clicked().connect( sigc::mem_fun(*this, &CurveEditor::curveResetPressed) );
|
||||||
|
|
||||||
@@ -52,7 +54,6 @@ CurveEditor::CurveEditor () : cl(NULL), activeParamControl(-1), realized(false),
|
|||||||
customCurveBox = new Gtk::VBox ();
|
customCurveBox = new Gtk::VBox ();
|
||||||
Gtk::HBox* tmpa = Gtk::manage (new Gtk::HBox ());
|
Gtk::HBox* tmpa = Gtk::manage (new Gtk::HBox ());
|
||||||
customCurve = Gtk::manage (new MyCurve ());
|
customCurve = Gtk::manage (new MyCurve ());
|
||||||
Gtk::Table* cctab = Gtk::manage (new Gtk::Table (2,1));
|
|
||||||
//Gtk::AspectFrame* af = Gtk::manage (new Gtk::AspectFrame ("",Gtk::ALIGN_CENTER,Gtk::ALIGN_CENTER,1,false));
|
//Gtk::AspectFrame* af = Gtk::manage (new Gtk::AspectFrame ("",Gtk::ALIGN_CENTER,Gtk::ALIGN_CENTER,1,false));
|
||||||
//af->add (*customCurve);
|
//af->add (*customCurve);
|
||||||
customCurve->set_size_request (GRAPH_SIZE+2*RADIUS, GRAPH_SIZE+2*RADIUS);
|
customCurve->set_size_request (GRAPH_SIZE+2*RADIUS, GRAPH_SIZE+2*RADIUS);
|
||||||
@@ -61,22 +62,51 @@ CurveEditor::CurveEditor () : cl(NULL), activeParamControl(-1), realized(false),
|
|||||||
tmpa->pack_start (*customCurve, true, false, 4);
|
tmpa->pack_start (*customCurve, true, false, 4);
|
||||||
customCurveBox->pack_start (*tmpa, true, true,4);
|
customCurveBox->pack_start (*tmpa, true, true,4);
|
||||||
|
|
||||||
Gtk::HBox* bbox = Gtk::manage (new Gtk::HBox ());
|
Gtk::HBox* custombbox = Gtk::manage (new Gtk::HBox ());
|
||||||
save = Gtk::manage (new Gtk::Button ());
|
saveCustom = Gtk::manage (new Gtk::Button ());
|
||||||
save->add (*Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-save"), Gtk::ICON_SIZE_BUTTON)));
|
saveCustom->add (*Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-save"), Gtk::ICON_SIZE_BUTTON)));
|
||||||
load = Gtk::manage (new Gtk::Button ());
|
loadCustom = Gtk::manage (new Gtk::Button ());
|
||||||
load->add (*Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-open"), Gtk::ICON_SIZE_BUTTON)));
|
loadCustom->add (*Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-open"), Gtk::ICON_SIZE_BUTTON)));
|
||||||
|
|
||||||
bbox->pack_end (*save, Gtk::PACK_EXPAND_WIDGET, 4);
|
custombbox->pack_end (*saveCustom, Gtk::PACK_EXPAND_WIDGET, 4);
|
||||||
bbox->pack_end (*load, Gtk::PACK_EXPAND_WIDGET, 4);
|
custombbox->pack_end (*loadCustom, Gtk::PACK_EXPAND_WIDGET, 4);
|
||||||
|
|
||||||
customCurveBox->pack_end (*bbox, Gtk::PACK_SHRINK, 2);
|
customCurveBox->pack_end (*custombbox, Gtk::PACK_SHRINK, 2);
|
||||||
customCurveBox->show_all ();
|
customCurveBox->show_all ();
|
||||||
|
|
||||||
save->signal_clicked().connect( sigc::mem_fun(*this, &CurveEditor::savePressed) );
|
saveCustom->signal_clicked().connect( sigc::mem_fun(*this, &CurveEditor::savePressed) );
|
||||||
load->signal_clicked().connect( sigc::mem_fun(*this, &CurveEditor::loadPressed) );
|
loadCustom->signal_clicked().connect( sigc::mem_fun(*this, &CurveEditor::loadPressed) );
|
||||||
save->set_tooltip_text (M("CURVEEDITOR_TOOLTIPSAVE"));
|
saveCustom->set_tooltip_text (M("CURVEEDITOR_TOOLTIPSAVE"));
|
||||||
load->set_tooltip_text (M("CURVEEDITOR_TOOLTIPLOAD"));
|
loadCustom->set_tooltip_text (M("CURVEEDITOR_TOOLTIPLOAD"));
|
||||||
|
|
||||||
|
// NURBS curve
|
||||||
|
NURBSCurveBox = new Gtk::VBox ();
|
||||||
|
Gtk::HBox* tmpb = Gtk::manage (new Gtk::HBox ());
|
||||||
|
NURBSCurve = Gtk::manage (new MyCurve ());
|
||||||
|
//Gtk::AspectFrame* af = Gtk::manage (new Gtk::AspectFrame ("",Gtk::ALIGN_CENTER,Gtk::ALIGN_CENTER,1,false));
|
||||||
|
//af->add (*customCurve);
|
||||||
|
NURBSCurve->set_size_request (GRAPH_SIZE+2*RADIUS, GRAPH_SIZE+2*RADIUS);
|
||||||
|
NURBSCurve->setType (NURBS);
|
||||||
|
//customCurve->set_tooltip_text (M("CURVEEDITOR_TOOLTIPMOVESPEED"));
|
||||||
|
tmpb->pack_start (*NURBSCurve, true, false, 4);
|
||||||
|
NURBSCurveBox->pack_start (*tmpb, true, true,4);
|
||||||
|
|
||||||
|
Gtk::HBox* NURBSbbox = Gtk::manage (new Gtk::HBox ());
|
||||||
|
saveNURBS = Gtk::manage (new Gtk::Button ());
|
||||||
|
saveNURBS->add (*Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-save"), Gtk::ICON_SIZE_BUTTON)));
|
||||||
|
loadNURBS = Gtk::manage (new Gtk::Button ());
|
||||||
|
loadNURBS->add (*Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-open"), Gtk::ICON_SIZE_BUTTON)));
|
||||||
|
|
||||||
|
NURBSbbox->pack_end (*saveNURBS, Gtk::PACK_EXPAND_WIDGET, 4);
|
||||||
|
NURBSbbox->pack_end (*loadNURBS, Gtk::PACK_EXPAND_WIDGET, 4);
|
||||||
|
|
||||||
|
NURBSCurveBox->pack_end (*NURBSbbox, Gtk::PACK_SHRINK, 2);
|
||||||
|
NURBSCurveBox->show_all ();
|
||||||
|
|
||||||
|
saveNURBS->signal_clicked().connect( sigc::mem_fun(*this, &CurveEditor::savePressed) );
|
||||||
|
loadNURBS->signal_clicked().connect( sigc::mem_fun(*this, &CurveEditor::loadPressed) );
|
||||||
|
saveNURBS->set_tooltip_text (M("CURVEEDITOR_TOOLTIPSAVE"));
|
||||||
|
loadNURBS->set_tooltip_text (M("CURVEEDITOR_TOOLTIPLOAD"));
|
||||||
|
|
||||||
// parametric curve
|
// parametric curve
|
||||||
paramCurveBox = new Gtk::VBox ();
|
paramCurveBox = new Gtk::VBox ();
|
||||||
@@ -92,10 +122,10 @@ CurveEditor::CurveEditor () : cl(NULL), activeParamControl(-1), realized(false),
|
|||||||
paramctab->attach (*paramCurve, 0, 1, 0, 1, Gtk::FILL, Gtk::SHRINK, 4, 4);
|
paramctab->attach (*paramCurve, 0, 1, 0, 1, Gtk::FILL, Gtk::SHRINK, 4, 4);
|
||||||
paramctab->attach (*shcSelector, 0, 1, 1, 2, Gtk::FILL, Gtk::SHRINK, RADIUS+4, 0);
|
paramctab->attach (*shcSelector, 0, 1, 1, 2, Gtk::FILL, Gtk::SHRINK, RADIUS+4, 0);
|
||||||
|
|
||||||
Gtk::HBox* tmpb = Gtk::manage (new Gtk::HBox ());
|
Gtk::HBox* tmpc = Gtk::manage (new Gtk::HBox ());
|
||||||
tmpb->pack_start (*paramctab, true, false);
|
tmpc->pack_start (*paramctab, true, false);
|
||||||
|
|
||||||
paramCurveBox->pack_start (*tmpb, true, true);
|
paramCurveBox->pack_start (*tmpc, true, true);
|
||||||
|
|
||||||
highlights = Gtk::manage (new Adjuster (M("CURVEEDITOR_HIGHLIGHTS"), -100, 100, 1, 0));
|
highlights = Gtk::manage (new Adjuster (M("CURVEEDITOR_HIGHLIGHTS"), -100, 100, 1, 0));
|
||||||
lights = Gtk::manage (new Adjuster (M("CURVEEDITOR_LIGHTS"), -100, 100, 1, 0));
|
lights = Gtk::manage (new Adjuster (M("CURVEEDITOR_LIGHTS"), -100, 100, 1, 0));
|
||||||
@@ -123,6 +153,7 @@ CurveEditor::CurveEditor () : cl(NULL), activeParamControl(-1), realized(false),
|
|||||||
paramCurveBox->reference ();
|
paramCurveBox->reference ();
|
||||||
|
|
||||||
customCurve->setCurveListener (this);
|
customCurve->setCurveListener (this);
|
||||||
|
NURBSCurve->setCurveListener (this);
|
||||||
paramCurve->setCurveListener (this);
|
paramCurve->setCurveListener (this);
|
||||||
shcSelector->setSHCListener (this);
|
shcSelector->setSHCListener (this);
|
||||||
|
|
||||||
@@ -196,11 +227,26 @@ void CurveEditor::savePressed () {
|
|||||||
|
|
||||||
std::ofstream f (fname.c_str());
|
std::ofstream f (fname.c_str());
|
||||||
std::vector<double> p = customCurve->getPoints ();
|
std::vector<double> p = customCurve->getPoints ();
|
||||||
|
|
||||||
|
switch (curveType->get_active_row_number()) {
|
||||||
|
case Spline: // custom
|
||||||
|
p = customCurve->getPoints ();
|
||||||
|
break;
|
||||||
|
case NURBS: // NURBS
|
||||||
|
p = NURBSCurve->getPoints ();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
int ix = 0;
|
int ix = 0;
|
||||||
if (p[ix++]<0)
|
if (p[ix]==(double)(Linear))
|
||||||
f << "Linear\n";
|
f << "Linear\n";
|
||||||
else
|
else if (p[ix]==(double)(Spline))
|
||||||
f << "Spline\n";
|
f << "Spline\n";
|
||||||
|
else if (p[ix]==(double)(NURBS))
|
||||||
|
f << "NURBS\n";
|
||||||
|
ix++;
|
||||||
for (int i=0; i<p.size()/2; i++, ix+=2)
|
for (int i=0; i<p.size()/2; i++, ix+=2)
|
||||||
f << p[ix] << ' ' << p[ix+1] << std::endl;
|
f << p[ix] << ' ' << p[ix+1] << std::endl;
|
||||||
f.close ();
|
f.close ();
|
||||||
@@ -233,9 +279,11 @@ void CurveEditor::loadPressed () {
|
|||||||
std::string s;
|
std::string s;
|
||||||
f >> s;
|
f >> s;
|
||||||
if (s=="Linear")
|
if (s=="Linear")
|
||||||
p.push_back (-1);
|
p.push_back ((double)(Linear));
|
||||||
else if (s=="Spline")
|
else if (s=="Spline")
|
||||||
p.push_back (1);
|
p.push_back ((double)(Spline));
|
||||||
|
else if (s=="NURBS")
|
||||||
|
p.push_back ((double)(NURBS));
|
||||||
else return;
|
else return;
|
||||||
double x;
|
double x;
|
||||||
while (f) {
|
while (f) {
|
||||||
@@ -243,10 +291,17 @@ void CurveEditor::loadPressed () {
|
|||||||
if (f)
|
if (f)
|
||||||
p.push_back (x);
|
p.push_back (x);
|
||||||
}
|
}
|
||||||
|
if (p[0] == (double)(Spline)) {
|
||||||
customCurve->setPoints (p);
|
customCurve->setPoints (p);
|
||||||
customCurve->queue_draw ();
|
customCurve->queue_draw ();
|
||||||
customCurve->notifyListener ();
|
customCurve->notifyListener ();
|
||||||
}
|
}
|
||||||
|
else if (p[0] == (double)(NURBS)) {
|
||||||
|
NURBSCurve->setPoints (p);
|
||||||
|
NURBSCurve->queue_draw ();
|
||||||
|
NURBSCurve->notifyListener ();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,21 +316,21 @@ void CurveEditor::setCurve (const std::vector<double>& c) {
|
|||||||
|
|
||||||
tmpCurve = c;
|
tmpCurve = c;
|
||||||
|
|
||||||
if (realized && curveType->get_active_row_number()<3) { // if it is not realized or "unchanged" is selected, just store the curve (prev line) and do not change gui
|
if (realized && curveType->get_active_row_number()<=Unchanged) { // if it is not realized or "unchanged" is selected, just store the curve (prev line) and do not change gui
|
||||||
|
|
||||||
typeconn.block(true);
|
typeconn.block(true);
|
||||||
if (c.size()==0 || c[0]==0) {
|
if (c.size()==0 || c[0]==(double)(Linear)) {
|
||||||
curveType->set_active (0);
|
curveType->set_active (Linear); // Change the combo selection
|
||||||
curveTypeIx = 0;
|
curveTypeIx = Linear;
|
||||||
}
|
}
|
||||||
else if (c[0]==1) {
|
else if (c[0]==(double)(Spline)) {
|
||||||
curveType->set_active (2);
|
curveType->set_active (Spline);
|
||||||
curveTypeIx = 2;
|
curveTypeIx = Spline;
|
||||||
customCurve->setPoints (c);
|
customCurve->setPoints (c);
|
||||||
}
|
}
|
||||||
else if (c[0]==2) {
|
else if (c[0]==(double)(Parametric)) {
|
||||||
curveType->set_active (1);
|
curveType->set_active (Parametric);
|
||||||
curveTypeIx = 1;
|
curveTypeIx = Parametric;
|
||||||
paramCurve->setPoints (c);
|
paramCurve->setPoints (c);
|
||||||
shcSelector->setPositions (c[1], c[2], c[3]);
|
shcSelector->setPositions (c[1], c[2], c[3]);
|
||||||
highlights->setValue (c[4]);
|
highlights->setValue (c[4]);
|
||||||
@@ -283,13 +338,21 @@ void CurveEditor::setCurve (const std::vector<double>& c) {
|
|||||||
darks->setValue (c[6]);
|
darks->setValue (c[6]);
|
||||||
shadows->setValue (c[7]);
|
shadows->setValue (c[7]);
|
||||||
}
|
}
|
||||||
|
else if (c[0]==(double)(NURBS)) {
|
||||||
|
curveType->set_active (NURBS);
|
||||||
|
curveTypeIx = NURBS;
|
||||||
|
NURBSCurve->setPoints (c);
|
||||||
|
}
|
||||||
removeIfThere (this, customCurveBox, false);
|
removeIfThere (this, customCurveBox, false);
|
||||||
removeIfThere (this, paramCurveBox, false);
|
removeIfThere (this, paramCurveBox, false);
|
||||||
|
removeIfThere (this, NURBSCurveBox, false);
|
||||||
|
|
||||||
if (curveType->get_active_row_number()==1)
|
if (curveType->get_active_row_number()==Spline)
|
||||||
pack_start (*paramCurveBox);
|
|
||||||
else if (curveType->get_active_row_number()==2)
|
|
||||||
pack_start (*customCurveBox);
|
pack_start (*customCurveBox);
|
||||||
|
else if (curveType->get_active_row_number()==Parametric)
|
||||||
|
pack_start (*paramCurveBox);
|
||||||
|
else if (curveType->get_active_row_number()==NURBS)
|
||||||
|
pack_start (*NURBSCurveBox);
|
||||||
|
|
||||||
typeconn.block(false);
|
typeconn.block(false);
|
||||||
}
|
}
|
||||||
@@ -297,17 +360,19 @@ void CurveEditor::setCurve (const std::vector<double>& c) {
|
|||||||
|
|
||||||
std::vector<double> CurveEditor::getCurve () {
|
std::vector<double> CurveEditor::getCurve () {
|
||||||
|
|
||||||
if (!realized || curveType->get_active_row_number()==3)
|
if (!realized || curveType->get_active_row_number()==Unchanged)
|
||||||
return tmpCurve;
|
return tmpCurve;
|
||||||
|
|
||||||
if (curveTypeIx<=0) {
|
// linear
|
||||||
|
if (curveTypeIx<=Linear) {
|
||||||
std::vector<double> lcurve (1);
|
std::vector<double> lcurve (1);
|
||||||
lcurve[0] = 0.0;
|
lcurve[0] = (double)(Linear);
|
||||||
return lcurve;
|
return lcurve;
|
||||||
}
|
}
|
||||||
else if (curveTypeIx==1) {
|
// parametric
|
||||||
|
else if (curveTypeIx==Parametric) {
|
||||||
std::vector<double> lcurve (8);
|
std::vector<double> lcurve (8);
|
||||||
lcurve[0] = 2.0;
|
lcurve[0] = (double)(Parametric);
|
||||||
shcSelector->getPositions (lcurve[1], lcurve[2], lcurve[3]);
|
shcSelector->getPositions (lcurve[1], lcurve[2], lcurve[3]);
|
||||||
lcurve[4] = highlights->getValue ();
|
lcurve[4] = highlights->getValue ();
|
||||||
lcurve[5] = lights->getValue ();
|
lcurve[5] = lights->getValue ();
|
||||||
@@ -315,22 +380,32 @@ std::vector<double> CurveEditor::getCurve () {
|
|||||||
lcurve[7] = shadows->getValue ();
|
lcurve[7] = shadows->getValue ();
|
||||||
return lcurve;
|
return lcurve;
|
||||||
}
|
}
|
||||||
else if (curveTypeIx==2)
|
// spline (custom)
|
||||||
|
else if (curveTypeIx==Spline)
|
||||||
return customCurve->getPoints ();
|
return customCurve->getPoints ();
|
||||||
|
// NURBS (control cage)
|
||||||
|
else if (curveTypeIx==NURBS)
|
||||||
|
return NURBSCurve->getPoints ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CurveEditor::typeSelectionChanged () {
|
void CurveEditor::typeSelectionChanged () {
|
||||||
|
|
||||||
removeIfThere (this, customCurveBox, false);
|
removeIfThere (this, customCurveBox, false);
|
||||||
removeIfThere (this, paramCurveBox, false);
|
removeIfThere (this, paramCurveBox, false);
|
||||||
|
removeIfThere (this, NURBSCurveBox, false);
|
||||||
|
|
||||||
if (curveType->get_active_row_number()==1)
|
if (curveType->get_active_row_number()==Spline) {
|
||||||
pack_start (*paramCurveBox);
|
|
||||||
else if (curveType->get_active_row_number()==2)
|
|
||||||
pack_start (*customCurveBox);
|
pack_start (*customCurveBox);
|
||||||
|
}
|
||||||
|
else if (curveType->get_active_row_number()==Parametric) {
|
||||||
|
pack_start (*paramCurveBox);
|
||||||
|
}
|
||||||
|
else if (curveType->get_active_row_number()==NURBS) {
|
||||||
|
pack_start (*NURBSCurveBox);
|
||||||
|
}
|
||||||
|
|
||||||
if (curveType->get_active_row_number()<3)
|
if (curveType->get_active_row_number() < Unchanged)
|
||||||
curveTypeIx = curveType->get_active_row_number();
|
curveTypeIx = (CurveType)curveType->get_active_row_number();
|
||||||
|
|
||||||
curveChanged ();
|
curveChanged ();
|
||||||
}
|
}
|
||||||
@@ -343,10 +418,13 @@ void CurveEditor::curveChanged () {
|
|||||||
|
|
||||||
void CurveEditor::curveResetPressed () {
|
void CurveEditor::curveResetPressed () {
|
||||||
switch (curveTypeIx) {
|
switch (curveTypeIx) {
|
||||||
case 2 : // Custom
|
case NURBS : // = Control cage
|
||||||
|
NURBSCurve->reset ();
|
||||||
|
break;
|
||||||
|
case Spline : // = Custom
|
||||||
customCurve->reset ();
|
customCurve->reset ();
|
||||||
break;
|
break;
|
||||||
case 1 : // Parametric
|
case Parametric :
|
||||||
highlights->resetPressed();
|
highlights->resetPressed();
|
||||||
lights->resetPressed();
|
lights->resetPressed();
|
||||||
darks->resetPressed();
|
darks->resetPressed();
|
||||||
@@ -399,7 +477,7 @@ void CurveEditor::setBatchMode (bool batchMode) {
|
|||||||
|
|
||||||
bool CurveEditor::isUnChanged () {
|
bool CurveEditor::isUnChanged () {
|
||||||
|
|
||||||
return curveType->get_active_row_number()==3;
|
return curveType->get_active_row_number()==Unchanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CurveEditor::setUnChanged (bool uc) {
|
void CurveEditor::setUnChanged (bool uc) {
|
||||||
@@ -408,7 +486,8 @@ void CurveEditor::setUnChanged (bool uc) {
|
|||||||
typeconn.block(true);
|
typeconn.block(true);
|
||||||
removeIfThere (this, customCurveBox, false);
|
removeIfThere (this, customCurveBox, false);
|
||||||
removeIfThere (this, paramCurveBox, false);
|
removeIfThere (this, paramCurveBox, false);
|
||||||
curveType->set_active (3);
|
removeIfThere (this, NURBSCurveBox, false);
|
||||||
|
curveType->set_active (Unchanged);
|
||||||
typeconn.block(false);
|
typeconn.block(false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -423,4 +502,5 @@ void CurveEditor::updateBackgroundHistogram (unsigned int* hist) {
|
|||||||
|
|
||||||
paramCurve->updateBackgroundHistogram (hist);
|
paramCurve->updateBackgroundHistogram (hist);
|
||||||
customCurve->updateBackgroundHistogram (hist);
|
customCurve->updateBackgroundHistogram (hist);
|
||||||
|
NURBSCurve->updateBackgroundHistogram (hist);
|
||||||
}
|
}
|
||||||
|
@@ -30,8 +30,10 @@ class CurveEditor : public Gtk::VBox, public CurveListener, public SHCListener,
|
|||||||
Gtk::Button* curve_reset;
|
Gtk::Button* curve_reset;
|
||||||
Gtk::VBox* paramCurveBox;
|
Gtk::VBox* paramCurveBox;
|
||||||
Gtk::VBox* customCurveBox;
|
Gtk::VBox* customCurveBox;
|
||||||
|
Gtk::VBox* NURBSCurveBox;
|
||||||
|
|
||||||
MyCurve* customCurve;
|
MyCurve* customCurve;
|
||||||
|
MyCurve* NURBSCurve;
|
||||||
MyCurve* paramCurve;
|
MyCurve* paramCurve;
|
||||||
SHCSelector* shcSelector;
|
SHCSelector* shcSelector;
|
||||||
|
|
||||||
@@ -40,14 +42,16 @@ class CurveEditor : public Gtk::VBox, public CurveListener, public SHCListener,
|
|||||||
Adjuster* darks;
|
Adjuster* darks;
|
||||||
Adjuster* shadows;
|
Adjuster* shadows;
|
||||||
|
|
||||||
Gtk::Button* save;
|
Gtk::Button* saveCustom;
|
||||||
Gtk::Button* load;
|
Gtk::Button* loadCustom;
|
||||||
|
Gtk::Button* saveNURBS;
|
||||||
|
Gtk::Button* loadNURBS;
|
||||||
|
|
||||||
CurveListener* cl;
|
CurveListener* cl;
|
||||||
|
|
||||||
bool realized;
|
bool realized;
|
||||||
std::vector<double> tmpCurve;
|
std::vector<double> tmpCurve;
|
||||||
int curveTypeIx;
|
CurveType curveTypeIx;
|
||||||
|
|
||||||
int activeParamControl;
|
int activeParamControl;
|
||||||
|
|
||||||
|
@@ -86,7 +86,7 @@ std::vector<double> MyCurve::get_vector (int veclen) {
|
|||||||
|
|
||||||
// calculate remaining points
|
// calculate remaining points
|
||||||
std::vector<double> curveDescr = getPoints ();
|
std::vector<double> curveDescr = getPoints ();
|
||||||
rtengine::Curve* rtcurve = new rtengine::Curve (curveDescr);
|
rtengine::Curve* rtcurve = new rtengine::Curve (curveDescr, veclen*1.5);
|
||||||
std::vector<double> t;
|
std::vector<double> t;
|
||||||
t.resize (veclen);
|
t.resize (veclen);
|
||||||
for (int i = 0; i < veclen; i++)
|
for (int i = 0; i < veclen; i++)
|
||||||
@@ -211,6 +211,25 @@ void MyCurve::draw (int width, int height, int handle) {
|
|||||||
cr->fill ();
|
cr->fill ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// draw the cage of the NURBS curve
|
||||||
|
if (curve.type==NURBS) {
|
||||||
|
std::valarray<double> ch_ds (1);
|
||||||
|
ch_ds[0] = 2;
|
||||||
|
cr->set_dash (ch_ds, 0);
|
||||||
|
cr->set_source_rgb (0.0, 0.0, 0.0);
|
||||||
|
std::vector<double> points = getPoints();
|
||||||
|
for (int i = 1; i < points.size(); ) {
|
||||||
|
double x = ((width-1) * points[i++] + 0.5)+RADIUS; // project (curve.x[i], 0, 1, width);
|
||||||
|
double y = height - ((height-1) * points[i++] + 0.5)+RADIUS; // project (curve.y[i], 0, 1, height);
|
||||||
|
if (i==3)
|
||||||
|
cr->move_to (x, y);
|
||||||
|
else
|
||||||
|
cr->line_to (x, y);
|
||||||
|
}
|
||||||
|
cr->stroke ();
|
||||||
|
cr->unset_dash ();
|
||||||
|
}
|
||||||
|
|
||||||
// draw curve
|
// draw curve
|
||||||
cr->set_source_rgb (0.0, 0.0, 0.0);
|
cr->set_source_rgb (0.0, 0.0, 0.0);
|
||||||
cr->move_to (point[0].get_x(), point[0].get_y());
|
cr->move_to (point[0].get_x(), point[0].get_y());
|
||||||
@@ -258,15 +277,24 @@ bool MyCurve::handleEvents (GdkEvent* event) {
|
|||||||
int x = CLAMP ((tx - RADIUS), 0, width-1); // X position of the pointer from the origin of the graph
|
int x = CLAMP ((tx - RADIUS), 0, width-1); // X position of the pointer from the origin of the graph
|
||||||
int y = height-1 - CLAMP ((ty - RADIUS), 0, height-1); // Y position of the pointer from the origin of the graph
|
int y = height-1 - CLAMP ((ty - RADIUS), 0, height-1); // Y position of the pointer from the origin of the graph
|
||||||
|
|
||||||
unsigned int distance = ~0U;
|
unsigned int distance_x = ~0U, distance_y = ~0U;
|
||||||
int num = curve.x.size();
|
int num = curve.x.size();
|
||||||
int closest_point = -1;
|
int closest_point = -1;
|
||||||
|
|
||||||
if (curve.type!=Parametric) {
|
if (curve.type!=Parametric) {
|
||||||
for (int i = 0; i < num; ++i) {
|
for (int i = 0; i < num; ++i) {
|
||||||
int cx = (int)((width-1) * curve.x[i] + 0.5); //project (c->ctlpoint[i][0], min_x, c->max_x, width);
|
int cx = (int)((width-1) * curve.x[i] + 0.5); //project (c->ctlpoint[i][0], min_x, c->max_x, width);
|
||||||
if ((unsigned int) abs (x - cx) < distance) {
|
int cy = (int)((height-1) * curve.y[i] + 0.5); //project (c->ctlpoint[i][0], min_x, c->max_x, width);
|
||||||
distance = abs (x - cx);
|
unsigned int curr_dist_x = abs (x - cx);
|
||||||
|
unsigned int curr_dist_y = abs (y - cy);
|
||||||
|
if (curr_dist_x < distance_x) {
|
||||||
|
distance_x = curr_dist_x;
|
||||||
|
distance_y = curr_dist_y;
|
||||||
|
closest_point = i;
|
||||||
|
}
|
||||||
|
else if (curr_dist_x == distance_x && curr_dist_y < distance_y) {
|
||||||
|
// there is mode than 1 point for that X coordinate, we select the point closest to the cursor
|
||||||
|
distance_y = curr_dist_y;
|
||||||
closest_point = i;
|
closest_point = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -295,7 +323,7 @@ bool MyCurve::handleEvents (GdkEvent* event) {
|
|||||||
rt_display->get_pointer(cursor_x, cursor_y, mod_type);
|
rt_display->get_pointer(cursor_x, cursor_y, mod_type);
|
||||||
|
|
||||||
new_type = CSEmpty;
|
new_type = CSEmpty;
|
||||||
if (distance > MIN_DISTANCE) {
|
if (distance_x > MIN_DISTANCE) {
|
||||||
/* insert a new control point */
|
/* insert a new control point */
|
||||||
if (num > 0) {
|
if (num > 0) {
|
||||||
int cx = (int)((width-1)*curve.x[closest_point]+0.5);
|
int cx = (int)((width-1)*curve.x[closest_point]+0.5);
|
||||||
@@ -350,7 +378,7 @@ bool MyCurve::handleEvents (GdkEvent* event) {
|
|||||||
draw (width, height, lit_point);
|
draw (width, height, lit_point);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (distance <= MIN_DISTANCE) {
|
if (distance_x <= MIN_DISTANCE) {
|
||||||
new_type = CSMove;
|
new_type = CSMove;
|
||||||
lit_point = closest_point;
|
lit_point = closest_point;
|
||||||
}
|
}
|
||||||
@@ -376,11 +404,11 @@ bool MyCurve::handleEvents (GdkEvent* event) {
|
|||||||
case Gdk::MOTION_NOTIFY:
|
case Gdk::MOTION_NOTIFY:
|
||||||
mevent = (GdkEventMotion *) event;
|
mevent = (GdkEventMotion *) event;
|
||||||
|
|
||||||
if (curve.type == Linear || curve.type == Spline) {
|
if (curve.type == Linear || curve.type == Spline || curve.type == NURBS) {
|
||||||
if (grab_point == -1) {
|
if (grab_point == -1) {
|
||||||
int previous_lit_point = lit_point;
|
int previous_lit_point = lit_point;
|
||||||
/* if no point is grabbed... */
|
/* if no point is grabbed... */
|
||||||
if (distance <= MIN_DISTANCE) {
|
if (distance_x <= MIN_DISTANCE) {
|
||||||
new_type = CSMove;
|
new_type = CSMove;
|
||||||
lit_point = closest_point;
|
lit_point = closest_point;
|
||||||
}
|
}
|
||||||
@@ -501,15 +529,19 @@ std::vector<double> MyCurve::getPoints () {
|
|||||||
|
|
||||||
std::vector<double> result;
|
std::vector<double> result;
|
||||||
if (curve.type==Parametric) {
|
if (curve.type==Parametric) {
|
||||||
result.push_back (+2.0);
|
result.push_back ((double)(Parametric));
|
||||||
for (int i=0; i<curve.x.size(); i++)
|
for (int i=0; i<curve.x.size(); i++)
|
||||||
result.push_back (curve.x[i]);
|
result.push_back (curve.x[i]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// the first value gives the type of the curve
|
||||||
if (curve.type==Linear)
|
if (curve.type==Linear)
|
||||||
result.push_back (-1.0);
|
result.push_back ((double)(Linear));
|
||||||
else
|
else if (curve.type==Spline)
|
||||||
result.push_back (+1.0);
|
result.push_back ((double)(Spline));
|
||||||
|
else if (curve.type==NURBS)
|
||||||
|
result.push_back ((double)(NURBS));
|
||||||
|
// then we push all the points coordinate
|
||||||
for (int i=0; i<curve.x.size(); i++)
|
for (int i=0; i<curve.x.size(); i++)
|
||||||
if (curve.x[i]>=0) {
|
if (curve.x[i]>=0) {
|
||||||
result.push_back (curve.x[i]);
|
result.push_back (curve.x[i]);
|
||||||
@@ -522,19 +554,15 @@ std::vector<double> MyCurve::getPoints () {
|
|||||||
void MyCurve::setPoints (const std::vector<double>& p) {
|
void MyCurve::setPoints (const std::vector<double>& p) {
|
||||||
|
|
||||||
int ix = 0;
|
int ix = 0;
|
||||||
int t = p[ix++];
|
CurveType t = (CurveType)p[ix++];
|
||||||
if (t==2) {
|
curve.type = t;
|
||||||
curve.type = Parametric;
|
if (t==Parametric) {
|
||||||
curve.x.clear ();
|
curve.x.clear ();
|
||||||
curve.y.clear ();
|
curve.y.clear ();
|
||||||
for (int i=1; i<p.size(); i++)
|
for (int i=1; i<p.size(); i++)
|
||||||
curve.x.push_back (p[ix++]);
|
curve.x.push_back (p[ix++]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (t==1)
|
|
||||||
curve.type = Spline;
|
|
||||||
else
|
|
||||||
curve.type = Linear;
|
|
||||||
curve.x.clear ();
|
curve.x.clear ();
|
||||||
curve.y.clear ();
|
curve.y.clear ();
|
||||||
for (int i=0; i<p.size()/2; i++) {
|
for (int i=0; i<p.size()/2; i++) {
|
||||||
@@ -609,6 +637,7 @@ void MyCurve::reset() {
|
|||||||
|
|
||||||
switch (curve.type) {
|
switch (curve.type) {
|
||||||
case Spline :
|
case Spline :
|
||||||
|
case NURBS :
|
||||||
curve.x.clear();
|
curve.x.clear();
|
||||||
curve.y.clear();
|
curve.y.clear();
|
||||||
curve.x.push_back(0.);
|
curve.x.push_back(0.);
|
||||||
@@ -624,5 +653,5 @@ void MyCurve::reset() {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//draw(width, height, -1);
|
draw(width, height, -1);
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,16 @@
|
|||||||
#define MIN_DISTANCE 8 /* min distance between control points */
|
#define MIN_DISTANCE 8 /* min distance between control points */
|
||||||
#define GRAPH_SIZE 200 /* size of the curve editor graphic */
|
#define GRAPH_SIZE 200 /* size of the curve editor graphic */
|
||||||
|
|
||||||
enum CurveType {Linear, Spline, Parametric};
|
// For compatibility and simplicity reason, order shouldn't change, and must be identical to the order specified in the curveType widget
|
||||||
|
enum CurveType {
|
||||||
|
Empty = -1,
|
||||||
|
Linear, // 0
|
||||||
|
Spline, // 1
|
||||||
|
Parametric, // 2
|
||||||
|
NURBS, // 3
|
||||||
|
// Insert new curve type above this line
|
||||||
|
Unchanged // Must remain the last of the enum
|
||||||
|
};
|
||||||
|
|
||||||
class CurveDescr {
|
class CurveDescr {
|
||||||
|
|
||||||
@@ -65,7 +74,7 @@ class MyCurve : public Gtk::DrawingArea {
|
|||||||
bool bghistvalid;
|
bool bghistvalid;
|
||||||
MyCurveIdleHelper* mcih;
|
MyCurveIdleHelper* mcih;
|
||||||
int cursor_x, cursor_y;
|
int cursor_x, cursor_y;
|
||||||
double ugp_x, ugp_y; // unclamped grabed point coordinates
|
double ugp_x, ugp_y; // unclamped grabbed point coordinates
|
||||||
|
|
||||||
void draw (int width, int height, int handle);
|
void draw (int width, int height, int handle);
|
||||||
void interpolate (int width, int height);
|
void interpolate (int width, int height);
|
||||||
|
Reference in New Issue
Block a user