Skip to content

Commit

Permalink
minor doc fixes, added member function to class Image
Browse files Browse the repository at this point in the history
  • Loading branch information
skramm committed Mar 20, 2024
1 parent b02b319 commit 21bece7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
8 changes: 4 additions & 4 deletions docs/homog2d_manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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).
<br>
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:
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions homog2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,9 @@ class Image
}
void drawText( std::string, Point2d_<float>, img::DrawParams dp=img::DrawParams() );

template<typename U>
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 )
Expand Down Expand Up @@ -789,6 +792,13 @@ So the drawing code checks if user has added some filling, and if so, does not a

}; // class DrawParams

template<typename IMG>
template<typename U>
void Image<IMG>::draw( const U& object, img::DrawParams dp )
{
object.draw( *this, dp );
}


} // namespace img

Expand Down
14 changes: 10 additions & 4 deletions misc/showcase/showcase14.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nbim; i++ )
{
img::Image<cv::Mat> im( 300, 220 );
poly1.draw( im, img::DrawParams().setColor(250,128,0) );
poly2.draw( im, img::DrawParams().setColor(250,0,128) );
img::Image<cv::Mat> 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();
Expand All @@ -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();
Expand Down

0 comments on commit 21bece7

Please sign in to comment.