diff --git a/docs/homog2d_manual.md b/docs/homog2d_manual.md index 847ebee..894f7da 100644 --- a/docs/homog2d_manual.md +++ b/docs/homog2d_manual.md @@ -892,7 +892,7 @@ auto right_pt = getExtremePoint( CardDir::Right, pol ); #### 3.4.6 - Distance between two Polyline objects You can get the closest distance between two points belonging to two polyline objects with `getClosestPoints()` (free function). -This will return an object on with you can fetch the corresponding pair of points, as indexes or as points, and the distance value: +This will return an object on which you can fetch the corresponding pair of points, as indexes or as points, and the distance value: ```C++ auto closest = getClosestPoints( poly1, poly2 ); auto ppts = closest.getPoints(); // get the points as a pair ("first" belongs to poly1, "second" to poly2) @@ -905,7 +905,7 @@ See [an example here](homog2d_showcase.md#sc14). You can check if it fullfilths the requirements to be a **simple polygon** (must be closed and no intersections).
-See [definition here](https://en.wikipedia.org/wiki/Simple_polygon)). +See [definition here](https://en.wikipedia.org/wiki/Simple_polygon). If it is, you can get its area and its centroid point: @@ -1758,11 +1758,11 @@ extended fine-tuning on how things are rendered, the goal is only to quickly see The user can select between two backends, both can be usable at the same time. They both are accessed through the templated datatype `Image`, lying in the sub-namespace `img`. -The two concrete types can be used as a type with `Image` are either `img::SvgImage`, to generate a SVG file, or Opencv `cv::Mat` type, +The two concrete types that can be used with `Image` are either `img::SvgImage`, to generate a SVG file, or Opencv `cv::Mat` type, that requires that the symbol `HOMOG2D_USE_OPENCV` is defined and that the library is installed on system. The difference between these two backends is that with SVG, you may only generate a file; -with OpenCv, you can build an interactive app, through the "HighGui" part of that library, whith mouse and keyboard callbacks. +with OpenCv, you can build an **interactive app**, through the "HighGui" part of that library, whith mouse and keyboard callbacks. This is demonstrated in a [provided demo program](../misc/demo_opencv.cpp) that you can try with: ``` $ make demo diff --git a/homog2d.hpp b/homog2d.hpp index d116163..25b4676 100644 --- a/homog2d.hpp +++ b/homog2d.hpp @@ -469,6 +469,9 @@ class Image } void drawText( std::string, Point2d_, img::DrawParams dp=img::DrawParams() ); + template + void draw( const U& object, img::DrawParams dp=img::DrawParams() ); + #ifdef HOMOG2D_USE_OPENCV /// Show image on window \c wname (not available for SVG !) void show( std::string wname ) @@ -789,6 +792,13 @@ So the drawing code checks if user has added some filling, and if so, does not a }; // class DrawParams +template +template +void Image::draw( const U& object, img::DrawParams dp ) +{ + object.draw( *this, dp ); +} + } // namespace img diff --git a/misc/showcase/showcase14.cpp b/misc/showcase/showcase14.cpp index 3dccf56..fc93021 100644 --- a/misc/showcase/showcase14.cpp +++ b/misc/showcase/showcase14.cpp @@ -33,14 +33,17 @@ int main( int argc, const char** argv ) CPolyline poly1( vpts1 ); CPolyline poly2( vpts2 ); poly2.translate(120,80); + poly1.translate(20,30); poly2.rotate( Rotate::CCW, Point2d(150, 150) ); auto extr_col = img::DrawParams().setColor(100,250,0).setPointStyle( img::PtStyle::Dot ); for( int i=0; i im( 300, 220 ); - poly1.draw( im, img::DrawParams().setColor(250,128,0) ); - poly2.draw( im, img::DrawParams().setColor(250,0,128) ); + img::Image im( 360, 280 ); +// poly1.draw( im, img::DrawParams().setColor(250,128,0) ); +// poly2.draw( im, img::DrawParams().setColor(250,0,128) ); + im.draw( poly1, img::DrawParams().setColor(250,128,0) ); + im.draw( poly2, img::DrawParams().setColor(250,0,128) ); auto res = poly1.intersects(poly2); // intersection points auto ptInt = res.get(); @@ -49,9 +52,12 @@ int main( int argc, const char** argv ) auto closest = getClosestPoints( poly1, poly2 ); auto ppts = closest.getPoints(); + draw( im, ppts ); Segment( closest.getPoints() ).draw( im, img::DrawParams().setColor(0,0,250) ); + getBB( poly1, poly2 ).draw( im, img::DrawParams().setColor(220,200,220) ); + im.drawText( "MinDist=" + std::to_string( closest.getMinDist() ), Point2d(20,20) ); - poly1.translate( 10, 6 ); + poly1.translate( 10, 7 ); poly2.translate( -7, -7 ); auto c2 = poly2.centroid();