Now the Lab curves are properly handeled in the history (MSG are still to be created)

This commit is contained in:
Hombre
2010-10-20 01:47:48 +02:00
parent b0d9c87621
commit 15c829cab2
7 changed files with 63 additions and 44 deletions

View File

@@ -52,6 +52,7 @@ Curve::Curve (const std::vector<double>& p, int poly_pn) : x(NULL), y(NULL), ypp
spline_cubic_set ();
else if (kind==NURBS && N > 2)
NURBS_set ();
else kind=Linear;
}
else if (kind==Parametric) {
if (p.size()!=8 && p.size()!=9)
@@ -110,7 +111,7 @@ void Curve::NURBS_set () {
std::vector<double> sc_x(nbSubCurvesPoints); // X sub-curve points ( XP0,XP1,XP2, XP2,XP3,XP4, ...)
std::vector<double> sc_y(nbSubCurvesPoints); // Y sub-curve points ( YP0,YP1,YP2, YP2,YP3,YP4, ...)
std::vector<double> sc_length(N-2); // Length of the subcurves
std::vector<double> sc_length(N+2); // Length of the subcurves
double total_length=0.;
// Create the list of Bezier sub-curves
@@ -159,24 +160,24 @@ void Curve::NURBS_set () {
total_length += length;
}
unsigned int total_points = 0;
for (unsigned int i=0; i < sc_x.size(); i+=3) {
total_points += (int)(((double)ppn+N-2) * sc_length[i/3] / total_length) + (i==0 ? 1 : 0) - 1;
}
poly_x.resize(total_points);
poly_y.resize(total_points);
poly_x.clear();
poly_y.clear();
unsigned int sc_xsize=j-1;
j = 0;
// create the polyline with the number of points adapted to the X range of the sub-curve
for (unsigned int i=0; i < sc_x.size(); i+=3) {
for (unsigned int i=0; i < sc_xsize /*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);
int nbr_points = (int)(((double)(ppn+N-2) * sc_length[i/3] )/ total_length);
if (nbr_points<0){
for(int it=0;it < sc_x.size(); it+=3) printf("sc_length[%d/3]=%f \n",it,sc_length[it/3]);
printf("NURBS: error detected!\n i=%d nbr_points=%d ppn=%d N=%d sc_length[i/3]=%f total_length=%f",i,nbr_points,ppn,N,sc_length[i/3],total_length);
exit(0);
}
// increment along the curve, not along the X axis
double increment = 1.0 / (double)(nbr_points-1);
if (!i) {
poly_x[j ] = sc_x[i];
poly_y[j++] = sc_y[i];
poly_x.push_back( sc_x[i]);
poly_y.push_back(sc_y[i]);
}
for (k=1; k<(nbr_points-1); k++) {
double t = k*increment;
@@ -186,12 +187,12 @@ void Curve::NURBS_set () {
double tr2t = tr*2*t;
// adding a point to the polyline
poly_x[j ] = tr2*sc_x[i] + tr2t*sc_x[i+1] + t2*sc_x[i+2];
poly_y[j++] = tr2*sc_y[i] + tr2t*sc_y[i+1] + t2*sc_y[i+2];
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[j ] = sc_x[i+2];
poly_y[j++] = sc_y[i+2];
poly_x.push_back( sc_x[i+2]);
poly_y.push_back(sc_y[i+2]);
}
}

View File

@@ -162,6 +162,6 @@ class Curve {
double getVal (double x);
void getVal (const std::vector<double>& t, std::vector<double>& res);
};
};
}
#endif

View File

@@ -412,8 +412,12 @@ void CurveEditor::typeSelectionChanged () {
void CurveEditor::curveChanged () {
if (cl)
if (cl) {
if (cl->isMulti())
cl->curveChanged (this);
else
cl->curveChanged ();
}
}
void CurveEditor::curveResetPressed () {

View File

@@ -19,10 +19,18 @@
#ifndef _CURVELISTENER_
#define _CURVELISTENER_
class CurveEditor;
class CurveListener {
private:
bool multi;
public:
virtual void curveChanged () {}
virtual void curveChanged (CurveEditor* ce) {}
void setMulti(bool value) { multi = value; }
bool isMulti() { return multi; }
CurveListener() : multi(false) {}
};
#endif

View File

@@ -68,14 +68,17 @@ LCurve::LCurve () : ToolPanel(), brAdd(false), contrAdd(false) {
lshape = Gtk::manage (new CurveEditor ());
lshape->show ();
lshape->setCurveListener (this);
CurveListener::setMulti(true);
ashape = Gtk::manage (new CurveEditor ());
ashape->show ();
ashape->setCurveListener (this);
CurveListener::setMulti(true);
bshape = Gtk::manage (new CurveEditor ());
bshape->show ();
bshape->setCurveListener (this);
CurveListener::setMulti(true);
pack_start (*lshape, Gtk::PACK_SHRINK, 4);
pack_start (*ashape, Gtk::PACK_SHRINK, 4);
@@ -158,11 +161,14 @@ void LCurve::setDefaults (const ProcParams* defParams, const ParamsEdited* pedit
}
}
void LCurve::curveChanged () {
void LCurve::curveChanged (CurveEditor* ce) {
if (listener) {
if (ce == lshape)
listener->panelChanged (EvLLCurve, M("HISTORY_CUSTOMCURVE"));
if (ce == ashape)
listener->panelChanged (EvLaCurve, M("HISTORY_CUSTOMCURVE"));
if (ce == bshape)
listener->panelChanged (EvLbCurve, M("HISTORY_CUSTOMCURVE"));
}
}

View File

@@ -49,7 +49,7 @@ class LCurve : public Gtk::VBox, public AdjusterListener, public ToolPanel, publ
void setBatchMode (bool batchMode);
void setAdjusterBehavior (bool bradd, bool contradd, bool satadd);
void curveChanged ();
void curveChanged (CurveEditor* ce);
void adjusterChanged (Adjuster* a, double newval);
void updateCurveBackgroundHistogram (unsigned* hist);
};