Laxkit
0.0.7.1
|
Plain old ordinary cubic tensor product patches, the base for mesh gradients and some image warping. More...
Public Member Functions | |
PatchData () | |
Creates a patch with points=NULL, size=0. | |
PatchData (double xx, double yy, double ww, double hh, int nr, int nc, unsigned int stle) | |
Creates a new patch in rect xx,yy,ww,hh with nr rows and nc columns. | |
virtual const char * | whattype () |
virtual SomeData * | duplicate (SomeData *dup) |
virtual void | FindBBox () |
Find bbox. | |
virtual int | pointin (flatpoint pp, int pin=1) |
Informational functions | |
virtual int | hasColorData () |
This is called from renderToBuffer, before rendering to see if there is anything to render. | |
virtual flatpoint | getControlPoint (int r, int c) |
Return points[r*xsize+c]. | |
virtual flatpoint | getPoint (double t, double s) |
Return the point corresponding to (s,t), where s and t are in range [0..1]. s for column, t for row. | |
virtual flatpoint * | bezAtEdge (flatpoint *p, int i, int row) |
Return a bezier curve corresponding to the row (row==1) or column (row==0) i. | |
virtual flatpoint * | bezCrossSection (flatpoint *p, int i, double t, int row) |
Return the cross section bezier curve at subpatch row (or column) i, and parameter t. | |
virtual int | bezOfPatch (flatpoint *p, int r, int rl, int c, int cl) |
Return the bezier outline of a subsection of the patch. | |
virtual void | resolveToSubpatch (double s, double t, int &c, double &ss, int &r, double &tt) |
From a point s,t (range 0..1), return the subpatch r,c plus offset into that subpatch. | |
virtual void | resolveFromSubpatch (int c, double ss, int r, double tt, double &s, double &t) |
From subpatch (r,c) and offset, return a point s,t with range [0..1],[0..1]. | |
virtual void | getGt (double *G, int roffset, int coffset, int isfory) |
See subdivide() for what Gt is. | |
virtual int | inSubPatch (flatpoint p, int *r_ret, int *c_ret, double *t_ret, double *s_ret, double d) |
Return which subpatch the point seems to be in. | |
virtual int | coordsInSubPatch (flatpoint p, int r, int c, double maxd, double *s_ret, double *t_ret) |
Find an approximate (s,t) point to p. | |
virtual int | WhatColor (double s, double t, Laxkit::ScreenColor *color_ret) |
Put the color at (s,t) into color_ret. | |
Data modifying functions | |
virtual void | Set (double xx, double yy, double ww, double hh, int nr, int nc, unsigned int stle) |
Set in rect xx,yy,ww,hh with nr rows and nc columns. Removes old info. | |
virtual void | zap (flatpoint p, flatpoint x, flatpoint y) |
Remap to be in parallelogram of p,x,y. | |
virtual void | zap () |
Remap so the patch corresponds to its rectangular bounding box. | |
virtual int | subdivide (int r, double rt, int c, double ct) |
Subdivide a single row number r, position rt, and a single column c, position ct. | |
virtual int | subdivide (int xn=2, int yn=2) |
Break each patch into subpatches. | |
virtual void | grow (int where, double *tr) |
Grow the patch off an edge. | |
virtual void | collapse (int rr, int cc) |
Merge (delete) rows, and/or columns. | |
virtual void | InterpolateControls (int whichcontrols) |
Interpolate control points according to whichcontrols. | |
virtual int | warpPatch (flatpoint center, double r1, double r2, double s, double e) |
Make data wrap inside a ring between radius 1 and 2, start angle s, end angle e. | |
I/O | |
virtual int | renderToBuffer (unsigned char *buffer, int bufw, int bufh, int bufstride, int bufdepth, int bufchannels) |
Write to buffer assuming samples are 8 bit ARGB. | |
virtual void | rpatchpoint (PatchRenderContext *context, flatpoint ul, flatpoint ur, flatpoint ll, flatpoint lr, double s1, double t1, double s2, double t2, int which) |
Recursive render. Used by renderToBuffer(). | |
virtual void | patchpoint (PatchRenderContext *context, double s0, double ds, double t0, double dt, int n) |
Called from renderToBuffer(). No recursion, just draw a bunch of rects for patch. | |
virtual void | dump_out (FILE *f, int indent, int what, Laxkit::anObject *context) |
virtual void | dump_in_atts (LaxFiles::Attribute *att, int flag, Laxkit::anObject *context) |
Reverse of the dump_out. | |
Public Member Functions inherited from LaxInterfaces::SomeData | |
virtual void | touchContents () |
virtual Laxkit::LaxImage * | GetPreview () |
If usepreview==1 and preview, then return preview. | |
virtual void | GeneratePreview (int w, int h) |
Create a preview image with transparency for a cached screen preview. | |
virtual const char * | Id () |
virtual const char * | Id (const char *newid) |
SomeData () | |
SomeData (double nminx, double nmaxx, double nminy, double nmaxy) | |
Constructor, setting the bounds. | |
virtual flatpoint | BBoxPoint (double x, double y, bool transform_to_parent) |
virtual flatpoint | ReferencePoint (int which, bool transform_to_parent) |
virtual int | fitto (double *boxm, DoubleBBox *box, double alignx, double aligny, int whentoscale=2) |
Fit this data to box. | |
virtual SomeData * | GetParent () |
virtual void | dump_in (FILE *f, int indent, Laxkit::anObject *context, LaxFiles::Attribute **Att=NULL) |
Dump in an attribute, then call dump_in_atts(thatatt,0). | |
virtual LaxFiles::Attribute * | dump_out_atts (LaxFiles::Attribute *att, int what, Laxkit::anObject *savecontext) |
Public Member Functions inherited from Laxkit::anObject | |
anObject () | |
Set object_id=getUniqueNumber(). | |
virtual | ~anObject () |
Empty virtual destructor. | |
virtual anObject * | duplicate (anObject *ref=NULL) |
virtual int | inc_count () |
Increment the data's count by 1. Returns count. | |
virtual int | dec_count () |
Decrement the count of the data, deleting if count is less than or equal to 0. | |
virtual int | the_count () |
Public Member Functions inherited from Laxkit::Affine | |
Affine (const double *m) | |
If mm==NULL, set identity. | |
Affine (const Affine &m) | |
Affine (double xx, double xy, double yx, double yy, double tx, double ty) | |
Affine & | operator= (Affine const &m) |
Affine & | operator*= (Affine const &m) |
Affine | operator* (Affine const m) |
virtual void | set (Affine a) |
virtual void | setIdentity () |
virtual bool | isIdentity () |
virtual void | setRotation (double angle) |
virtual void | setScale (double sx, double sy) |
virtual void | setBasis (flatpoint o, flatpoint x, flatpoint y) |
virtual void | setBasics (double x, double y, double sx, double sy, double angle, double shear) |
virtual void | getBasics (double *x, double *y, double *sx, double *sy, double *angle, double *shear) |
virtual void | Translate (flatvector d) |
virtual void | Rotate (double angle) |
virtual void | Rotate (double angle, flatpoint around_point) |
virtual void | RotatePointed (flatpoint anchor1, flatpoint anchor2, flatpoint newanchor2) |
virtual void | RotateScale (flatpoint anchor1, flatpoint anchor2, flatpoint newanchor2) |
Rotate and scale so that anchor1 stays fixed, but anchor2 is shifted to newanchor2. | |
virtual void | Stretch (flatpoint anchor1, flatpoint anchor2, flatpoint newanchor2) |
virtual void | AnchorShear (flatpoint anchor1, flatpoint anchor2, flatpoint anchor3, flatpoint newanchor3) |
Transform so that anchor1 and 2 stay fixed, but anchor3 is shifted to newanchor3. | |
virtual void | Scale (double s) |
virtual void | Scale (flatpoint o, double s) |
Scale around point o. | |
virtual void | Scale (flatpoint o, double sx, double sy) |
virtual void | Scale (flatpoint anchor1, flatpoint anchor2, flatpoint newanchor2) |
Scale as if you move anchor2 to newanchor2, while anchor1 stays the same. | |
virtual void | FlipH () |
virtual void | FlipV () |
virtual void | Flip (flatpoint f1, flatpoint f2) |
Flip across the axis of f1 to f2. | |
virtual void | Multiply (Affine &m) |
this=this*m | |
virtual void | PreMultiply (Affine &m) |
this=m*this | |
virtual Affine | Inversion () |
Return a new matrix that is the inverse of this, if possible. | |
virtual void | Invert () |
Make this the inverse of whatever it is. | |
virtual flatpoint | transformPoint (flatpoint p) |
virtual flatpoint | transformPointInverse (flatpoint p) |
virtual flatpoint | transformVector (flatpoint p) |
Apply the transfrom, but ignore this's translation component. | |
virtual const double * | m () const |
virtual void | m (const double *mm) |
virtual void | m (double xx, double xy, double yx, double yy, double tx, double ty) |
virtual double | m (int c) |
virtual void | m (int c, double v) |
virtual void | Unshear (int preserve_x, int normalize) |
Clear shearing and unequal scaling. Null vectors stay null vectors. | |
virtual void | Normalize () |
Make x and y both be unit vectors, but point in the same direction as before. | |
virtual flatpoint | origin () |
virtual void | origin (flatpoint o) |
virtual flatpoint | xaxis () |
virtual void | xaxis (flatpoint x) |
virtual flatpoint | yaxis () |
virtual void | yaxis (flatpoint y) |
Public Member Functions inherited from Laxkit::DoubleBBox | |
DoubleBBox () | |
Create empty invalid bbox (maxx<minx and maxy<miny). | |
DoubleBBox (flatpoint p) | |
Create box whose bounds are p. | |
DoubleBBox (double mix, double max, double miy, double may) | |
Create box whose bounds are as given. | |
virtual void | clear () |
Make box invalid: set minx=miny=0 and maxx=maxy=-1. | |
virtual void | addtobounds (double x, double y) |
virtual void | addtobounds (flatpoint p) |
Expand bounds to contain p. Set the bounds to p if current bounds are invalid. | |
virtual void | addtobounds (DoubleBBox *bbox) |
Add the bbox to the bounds. Set the bounds if current bounds are invalid. | |
virtual void | addtobounds (const double *m, DoubleBBox *bbox) |
Add bbox to bounds, first transforming it by 6 element transform matrix m. | |
virtual void | setbounds (DoubleBBox *bbox) |
Just copy over the bounds. | |
virtual void | setbounds (flatpoint *pts, int n) |
Make this bbox be the bounds for the given n points. (does not add to previous bounds) | |
virtual void | setbounds (double mix, double max, double miy, double may) |
Set the bounds to the specified values. | |
virtual int | validbounds () |
Returns maxx>=minx && maxy>=miny. | |
virtual int | intersect (double mix, double max, double miy, double may, int settointersection=0) |
Intersect the given bounds with this's bounds. Return 1 for non-empty intersection. | |
virtual int | intersect (DoubleBBox *bbox, int settointersection=0) |
Just return intersect(bbox.minx,...,settointersection). | |
virtual int | intersect (double *m, DoubleBBox *bbox, int touching, int settointersection) |
Does the transformed box touch. **** incomplete implementation. | |
virtual int | boxcontains (double x, double y) |
Return whether the given point is contained within or on the bounds. | |
virtual flatpoint | BBoxPoint (double x, double y) |
Public Attributes | |
int | renderdepth |
How and how much to render in renderToBuffer. | |
int | griddivisions |
flatpoint * | points |
int | xsize |
int | ysize |
unsigned int | style |
PatchControls | controls |
LineStyle | linestyle |
Public Attributes inherited from LaxInterfaces::SomeData | |
Laxkit::LaxImage * | preview |
A preview image potentially to be used to not have to rerender on each refresh. | |
int | usepreview |
Flag for whether to use SomeData::preview rather than rendering. | |
std::time_t | previewtime |
The time the preview was generated, if at all, as returned by time(). | |
std::time_t | modtime |
The time of last modification through a SomeData function. | |
int | bboxstyle |
flatpoint | centerpoint |
unsigned int | flags |
int | iid |
Id of the interface that should handle this data. | |
char * | nameid |
Public Attributes inherited from Laxkit::anObject | |
int | suppress_debug |
DeleteRefCountedFunc | deleteMe |
Called when the count is decremented to 0. | |
unsigned long | object_id |
char * | object_idstr |
Public Attributes inherited from Laxkit::DoubleBBox | |
double | minx |
double | maxx |
double | miny |
double | maxy |
Plain old ordinary cubic tensor product patches, the base for mesh gradients and some image warping.
See PatchInterface.
Return a bezier curve corresponding to the row (row==1) or column (row==0) i.
This is similar to bezCrossSection(), but only for subpatch edges.
Returns a list v-c-c-v-c-c-v-...-v. If p==NULL, return a new flatpoint[]. Otherwise, if row==0, p must be at least ysize long, and if row!=0, it must be at least xsize long.
i==1,row==0 corresponds to point column 3.
If i is out of range, NULL is returned.
Referenced by LaxInterfaces::PatchInterface::Refresh().
|
virtual |
Return the cross section bezier curve at subpatch row (or column) i, and parameter t.
Returns a list v-c-c-v-c-c-v-...-v. If p==NULL, return a new flatpoint[]. Otherwise, if row==0, p must be at least ysize long, and if row!=0, it must be at least xsize long.
i==1 corresponds to point column 3.
You must not pass an i at a far edge.
References Laxkit::bez_point().
Referenced by LaxInterfaces::PatchInterface::MouseMove().
Return the bezier outline of a subsection of the patch.
The returned path will enclose a section rl subpatches wide and cl subpatches tall. r, rl, c, and cl are subpatch indices, not indices into points. So the point row of the start of r is 3*r. If rl<1 then use the maximum size from row r. Similarly for cl.
If p==NULL, then return the number of points that must be allocated in p. Otherwise, p must have enough points for the requested data.
Returns a closed path, with the first vertex at p[1], whose associated control points are p[0] and p[2].
Referenced by inSubPatch().
Merge (delete) rows, and/or columns.
r and c are subpatch indices, not point indices. So to merge the first column of patches and the next column of patches, then pass c=1.
If c==1 then the first column is removed. Same goes for when c is the last column. Similar for rows.
If c<0, then no columns are deleted. Similarly for when r<0.
If r>=0 and c>=0, then columns are merged first, then rows.
Reimplemented in LaxInterfaces::ColorPatchData.
|
virtual |
Find an approximate (s,t) point to p.
Assumes that it is known that point p is in the subpatch r,c.
This works by computing 16 points within the range (s0..s1,t0..t1), and comparing their distance to p. Using the point with the minimum distance to p, try the same thing with the range (s-ds..s+ds,t-dt..t+dt), where dt and ds are a fraction of the original range.
Once a point is found that is less than maxd from p, then return that point.
Returns 0 for s_ret and t_ret set, else nonzero.
References LaxInterfaces::B, LaxInterfaces::dot(), getGt(), LaxInterfaces::getT(), LaxInterfaces::m_times_m(), and LaxInterfaces::m_times_v().
Referenced by inSubPatch().
|
virtual |
Find bbox.
Reimplemented from LaxInterfaces::SomeData.
Referenced by LaxInterfaces::ImagePatchData::dump_in_atts(), LaxInterfaces::ColorPatchData::dump_in_atts(), LaxInterfaces::EngraverFillData::dump_in_atts(), dump_in_atts(), grow(), LaxInterfaces::PatchInterface::MouseMove(), LaxInterfaces::ImagePatchInterface::newPatchData(), LaxInterfaces::ColorPatchInterface::newPatchData(), LaxInterfaces::EngraverFillInterface::newPatchData(), LaxInterfaces::PatchInterface::newPatchData(), warpPatch(), LaxInterfaces::ImagePatchData::zap(), and zap().
See subdivide() for what Gt is.
This Gt refers only to the one 4x4 coordinate section starting at (roffset,coffset).
roffset and coffset are point indices, not subpatch indices.
Referenced by coordsInSubPatch(), LaxInterfaces::ColorPatchInterface::drawpatch(), LaxInterfaces::ImagePatchInterface::drawpatch(), LaxInterfaces::PatchInterface::drawpatch(), getPoint(), renderToBuffer(), and subdivide().
|
virtual |
Return the point corresponding to (s,t), where s and t are in range [0..1]. s for column, t for row.
Please note that this is useful only for one time lookup. The matrices involved are not cached for repeated use.
References LaxInterfaces::B, LaxInterfaces::dot(), getGt(), LaxInterfaces::getT(), LaxInterfaces::m_times_m(), LaxInterfaces::m_times_v(), and resolveToSubpatch().
Referenced by LaxInterfaces::EngraverFillData::Sync().
|
virtual |
Grow the patch off an edge.
If where==0, add a column to the left. If where==1, add a row to the top. If where==2, add a column to the right. If where==3, add a row to the bottom.
The new edge is the tr(oldedge), and the intervening controls are interpolated. tr is a 6 member affine transform.
Reimplemented in LaxInterfaces::ColorPatchData.
References FindBBox(), and Laxkit::transform_point().
|
virtual |
This is called from renderToBuffer, before rendering to see if there is anything to render.
This is useful, for instance, in an ImagePatchdata, which will not want to render if there is no loaded image.
Subclasses will redefine this. Default here is to return 0.
Reimplemented in LaxInterfaces::ColorPatchData, and LaxInterfaces::ImagePatchData.
Referenced by renderToBuffer().
|
virtual |
Return which subpatch the point seems to be in.
If t_ret!=NULL and s_ret!=NULL, then also find the s_ret (x direction) and t_ret (y direction) within the subpatch (range [0..1] the point is at, and put those values in t_ret and s_ret.
r_ret and c_ret can alsa be NULL, if the specific row and column are not needed.
The return value is 0 for point not found to be within the boundary of any subpatch, or nonzero if it is. Note that this only checks against the bezier boundary points, not the actual visual boundary of the patch, which might go past the bez boundary if the inner controls are dragged way out.
References bezOfPatch(), coordsInSubPatch(), and Laxkit::point_is_in_bez().
Referenced by LaxInterfaces::PatchInterface::MouseMove().
|
virtual |
Interpolate control points according to whichcontrols.
This will not change the controls that exist for each type, but will change all the others as best as it knows how.
Referenced by LaxInterfaces::PatchInterface::MouseMove().
|
virtual |
Called from renderToBuffer(). No recursion, just draw a bunch of rects for patch.
The parameters refer to the color space. They are not coordinates.
n is the number of areas to divide the patch into. s0, t0, ds, dt all refer to the color space.
Finds coords via context->getPoint().
References LaxInterfaces::PatchRenderContext::getPoint(), LaxInterfaces::getT(), LaxInterfaces::renderTriangleToBuffer(), and WhatColor().
Reimplemented from LaxInterfaces::SomeData.
|
virtual |
Write to buffer assuming samples are 8 bit ARGB.
Blanks out the buffer, then renders the patch into it, if any.
Currently, buffer is width x height pixels, and must be 8bit ARGB.
Subclasses need not redefine this function, rpatchpoint(), or patchpoint(). They need only redefine WhatColor().
Reimplemented from LaxInterfaces::SomeData.
References LaxInterfaces::B, Laxkit::DoubleBBox::clear(), getGt(), hasColorData(), LaxInterfaces::m_times_m(), rpatchpoint(), and Laxkit::transform_point().
|
virtual |
From subpatch (r,c) and offset, return a point s,t with range [0..1],[0..1].
c and r are subpatch indices, not point indices. (Point column)=3*(subpatch column). If c,ss,r,tt don't exist in this patch, then a faulty s,t will be returned!
|
virtual |
From a point s,t (range 0..1), return the subpatch r,c plus offset into that subpatch.
If s,t are bad, then the returned values will be bad!
Referenced by getPoint(), and LaxInterfaces::ColorPatchData::WhatColor().
|
virtual |
Recursive render. Used by renderToBuffer().
Use Cx and Cy to find points: P = St C T. which is which point needs to be computed and colored still.
Also assumes s0,ds,t0, and dt set, which refer to the image section corresponding to the current subpatch. s1,t1, s2,t2 are between 0 and 1 for the current subpatch.
References LaxInterfaces::PatchRenderContext::getPoint(), LaxInterfaces::getT(), and WhatColor().
Referenced by renderToBuffer().
Subdivide a single row number r, position rt, and a single column c, position ct.
If r<0, then do not subdivide on a row. Same for when c<0. if r or c are to large, then do not subdivide.
r and c are border numbers, so r*3 is index int points. rt and ct are in the range [0..1], with rt==0 being row r, and rt==1 being row r+1.
Return 0 for success, nonzero for failure (nothing changed).
Reimplemented in LaxInterfaces::ColorPatchData.
References LaxInterfaces::B, LaxInterfaces::Binv, getGt(), LaxInterfaces::getPolyT(), LaxInterfaces::m_times_m(), and LaxInterfaces::m_transpose().
Referenced by LaxInterfaces::ColorPatchData::subdivide().
Break each patch into subpatches.
Break down into xn*yn subsubpatches. Say xn=2 and yn=3, then each subpatch gets split into 2 columns and 3 rows.
each subpatch is geared for values of s,t from 0 to 1.
transformed patch, with T=N*V, S=M*U: U = Ut Bt ((Bt^-1 Mt Bt) Gt (B N B^-1)) B V
Return 0 for success, nonzero for failure (nothing changed).
Reimplemented in LaxInterfaces::ColorPatchData.
References LaxInterfaces::B, LaxInterfaces::Binv, getGt(), LaxInterfaces::getPolyT(), LaxInterfaces::m_times_m(), and LaxInterfaces::m_transpose().
|
virtual |
Make data wrap inside a ring between radius 1 and 2, start angle s, end angle e.
Y will be mapped to the radii, and x the rings.
Return 0 for success, or non-negative for not enough points to warp.
References FindBBox(), norm(), and transpose().
|
virtual |
Put the color at (s,t) into color_ret.
Return 0 for color returned, or nonzero for not returned, as when the patch has no associated color data.
Reimplemented in LaxInterfaces::ColorPatchData, and LaxInterfaces::ImagePatchData.
Referenced by patchpoint(), and rpatchpoint().
Remap to be in parallelogram of p,x,y.
Assumes xsize,ysize,points already set and allocated properly, x and y are vectors
|
virtual |
Remap so the patch corresponds to its rectangular bounding box.
Reimplemented in LaxInterfaces::ImagePatchData.
References FindBBox().
Referenced by Set().
int LaxInterfaces::PatchData::renderdepth |
How and how much to render in renderToBuffer.
If renderdepth>=0, then render recursively to full pixel depth of render buffer. If renderdepth<0, then subdivide each subpatch by -renderdepth number of single color quadrilateral blocks.
Referenced by LaxInterfaces::ColorPatchData::ColorPatchData(), LaxInterfaces::ImagePatchData::ImagePatchData(), LaxInterfaces::ColorPatchInterface::newPatchData(), and PatchData().