Skip to content

Commit

Permalink
fixed drawing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
skramm committed Apr 21, 2024
1 parent 0de73d0 commit 75c513f
Show file tree
Hide file tree
Showing 22 changed files with 58 additions and 52 deletions.
47 changes: 30 additions & 17 deletions homog2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,22 @@ Image<cv::Mat>::write( std::string fname ) const
}
#endif // HOMOG2D_USE_OPENCV

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

template<typename IMG>
template<typename U,typename V>
void Image<IMG>::draw( const std::pair<U,V>& pairp, img::DrawParams dp )
{
pairp.first.draw( *this, dp );
pairp.second.draw( *this, dp );
}


} // namespace img


Expand Down Expand Up @@ -10582,30 +10598,29 @@ drawText( img::Image<U>& im, std::string str, Point2d_<FPT> pt, img::DrawParams
}

namespace priv {
#if 1
#ifdef HOMOG2D_USE_OPENCV
template<typename FPT>

/// Draw indexes for points
template<typename IMG,typename FPT>
void
impl_drawIndexes( img::Image<cv::Mat>& img, size_t c, const img::DrawParams& dp, const Point2d_<FPT>& pt )
impl_drawIndexes( img::Image<IMG>& img, size_t c, const img::DrawParams& dp, const Point2d_<FPT>& pt )
{
if( dp._dpValues._showIndex )
cv::putText( img.getReal(), std::to_string(c), pt.getCvPtd(), 0, 0.8, cv::Scalar( 250,0,0 ), 2 );
drawText( img, std::to_string(c), pt, dp );
}
template<typename FPT>

/// Draw indexes for segment
template<typename IMG,typename FPT>
void
impl_drawIndexes( img::Image<cv::Mat>& img, size_t c, const img::DrawParams& dp, const Segment_<FPT>& seg )
impl_drawIndexes( img::Image<IMG>& img, size_t c, const img::DrawParams& dp, const Segment_<FPT>& seg )
{
if( dp._dpValues._showIndex )
cv::putText( img.getReal(), std::to_string(c), seg.getCenter().getCvPtd(), 0, 0.8, cv::Scalar( 250,0,0 ), 2 );
drawText( img, std::to_string(c), seg.getCenter(), dp );
}
#endif
#endif


/// Default signature, will be instanciated if no other fits (and does nothing)
template<typename U,typename DUMMY>
template<typename IMG,typename DUMMY>
void
impl_drawIndexes( img::Image<U>&, size_t, const img::DrawParams&, const DUMMY& )
impl_drawIndexes( img::Image<IMG>&, size_t, const img::DrawParams&, const DUMMY& )
{}

} // namespace priv
Expand All @@ -10628,8 +10643,7 @@ void draw( img::Image<U>& img, const T& cont, const img::DrawParams& dp=img::Dra
for( const auto& elem: cont )
{
elem.draw( img, dp );
priv::impl_drawIndexes( img, c, dp, elem );
c++;
priv::impl_drawIndexes( img, c++, dp, elem );
}
}
/// This version holds a \c std::function as 3th parameter. It can be used to pass a function
Expand All @@ -10649,8 +10663,7 @@ void draw( img::Image<U>& img, const T& cont, std::function<img::DrawParams(int)
{
auto dp = func(c);
elem.draw( img, dp );
priv::impl_drawIndexes( img, c, dp, elem );
c++;
priv::impl_drawIndexes( img, c++, dp, elem );
}
}

Expand Down
2 changes: 0 additions & 2 deletions misc/showcase/showcase1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ int main( int, const char** )
auto im_h = 250;
Image<cv::Mat> myImg( im_w, im_h );

int offset_h = 100;
int offset_v = 60;
Homogr Hr( 2.*M_PI/nbim ); // set up rotation
Homogr HT1( im_w/2, 100 ); // centered on image center
Homogr HT2( -im_w/2, -100 );
Expand Down
3 changes: 1 addition & 2 deletions misc/showcase/showcase11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@

using namespace h2d;

int main( int argc, const char** argv )
int main( int, const char** )
{
auto nbim = 30; // nb images

uint8_t g = 100;
auto kx1 = 78;
auto ky1 = 30;
auto kx2 = 43;
Expand Down
2 changes: 1 addition & 1 deletion misc/showcase/showcase12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void processRot(
}
}

int main( int argc, const char** argv )
int main( int, const char** )
{
CPolyline pl;
std::vector<Point2d> vpts{
Expand Down
4 changes: 2 additions & 2 deletions misc/showcase/showcase13.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

using namespace h2d;

int main( int argc, const char** argv )
int main( int, const char** )
{
auto nbim = 20; // nb images

Expand All @@ -24,7 +24,7 @@ int main( int argc, const char** argv )
int nbpts = 1.0*rand() / RAND_MAX * (nbpts_max-nbpts_min) + nbpts_min;
std::vector<Point2d> vec(nbpts);
auto it = std::begin(vec);
for( auto i=0; i<nbpts; i++ )
for( auto j=0; j<nbpts; j++ )
*it++ = Point2d(
1.0*rand() / RAND_MAX * (cmax-cmin) + cmin,
1.0*rand() / RAND_MAX * (cmax-cmin) + cmin
Expand Down
2 changes: 1 addition & 1 deletion misc/showcase/showcase15.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

using namespace h2d;

int main( int argc, const char** argv )
int main( int, const char** )
{
auto nbim = 20; // nb images

Expand Down
2 changes: 1 addition & 1 deletion misc/showcase/showcase16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

using namespace h2d;

int main( int argc, const char** argv )
int main( int, const char** )
{
auto nbim = 25; // nb images
auto imsize = 300;
Expand Down
2 changes: 1 addition & 1 deletion misc/showcase/showcase17.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

using namespace h2d;

int main( int argc, const char** argv )
int main( int, const char** )
{
auto nbim = 30; // nb images
auto k = 60;
Expand Down
2 changes: 0 additions & 2 deletions misc/showcase/showcase18.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ int main( int, const char** )
auto nbim = 25; // nb images
auto Hdraw = Homogr().setScale(30).addTranslation(10,10);

auto r_w0 = 2;
auto r_h0 = 1;
auto x0 = 3.;
auto y0 = 2.;
auto k=1.8;
Expand Down
5 changes: 5 additions & 0 deletions misc/showcase/showcase19.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
\file
\brief Generates random segments
\todo 20240421 switch all showcases to Svg images, much nicer!
*/

#define HOMOG2D_USE_OPENCV
Expand Down Expand Up @@ -43,16 +45,19 @@ int main( int, const char** )
auto func = [&](int i) // lambda, needed to fetch color from index
{
return img::DrawParams().setColor(vcol[i]).showPoints();
// return img::DrawParams().showIndex().setColor(vcol[i]).showPoints();
};
std::function<img::DrawParams(int)> f(func);

for( int i=0; i<nbim; i++ )
{
auto vseg = generateSegments( nbSegs );
// Image<SvgImage> im( im_w, im_h );
Image<cv::Mat> im( im_w, im_h );
draw( im, vseg, f );

std::ostringstream ossa;
// ossa << "showcase19_" << std::setfill('0') << std::setw(2) << i << ".svg";
ossa << "showcase19_" << std::setfill('0') << std::setw(2) << i << ".png";
im.write( ossa.str() );
}
Expand Down
2 changes: 1 addition & 1 deletion misc/showcase/showcase2a.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using namespace h2d;
using namespace h2d::img;

int main( int argc, const char** argv )
int main( int, const char** )
{
int n=30;
auto im_w = 350;
Expand Down
2 changes: 1 addition & 1 deletion misc/showcase/showcase3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

using namespace h2d;

int main( int argc, const char** argv )
int main( int, const char** )
{
auto n = 25; // nb images
CPolyline pl;
Expand Down
10 changes: 5 additions & 5 deletions misc/showcase/showcase4a.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
using namespace h2d;
using namespace h2d::img;

int main( int argc, const char** argv )
int main( int, const char** )
{
auto nbim = 25; // nb images
auto Hdraw = Homogr().setScale(30).addTranslation(10,10);

auto r_w0 = 2;
auto r_h0 = 1;
auto x0 = 3.;
auto y0 = 1.;
// auto y0 = 1.;
auto k=1.8;
uint8_t g = 100;
for( int i=0; i<nbim; i++ )
Expand All @@ -31,12 +31,10 @@ int main( int argc, const char** argv )
Circle obj2( Point2d(-x1+x0,-y1+x0), 2.-.5*r_w );
auto bcir = obj1.getBoundingCircle();
auto cbb = getBB(obj2);
auto center = obj1.getCenter();

auto obj1_d = Hdraw * obj1;
auto obj2_d = Hdraw * obj2;
auto bcir_d = Hdraw * bcir;
auto center_d = Hdraw * center;
auto cbb_d = Hdraw * cbb;

Image<cv::Mat> ima( 250, 200 );
Expand All @@ -46,7 +44,9 @@ int main( int argc, const char** argv )
bcir_d.draw( ima, DrawParams().setColor(100,250,100) );
obj2_d.getBB().draw( ima, DrawParams().setColor(100,50,200) );

getBB(obj1_d, obj2_d).draw( ima, DrawParams().setColor(g,g,g) );
auto bb = getBB(obj1_d, obj2_d);
bb.draw( ima, DrawParams().setColor(g,g,g) );
bb.getBoundingCircle().draw( ima, DrawParams().setColor(50,50,125) );

std::ostringstream ossa;
ossa << "showcase4a_" << std::setfill('0') << std::setw(2) <<i << ".png";
Expand Down
3 changes: 1 addition & 2 deletions misc/showcase/showcase4b.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@

using namespace h2d;

int main( int argc, const char** argv )
int main( int, const char** )
{
auto nbim = 25; // nb images
auto Hdraw = Homogr().setScale(30).addTranslation(10,10);

auto r_w0 = 2;
auto r_h0 = 1;
auto x0 = 3.;
auto y0 = 1.;
auto k=1.8;

for( int i=0; i<nbim; i++ )
Expand Down
3 changes: 1 addition & 2 deletions misc/showcase/showcase5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@

using namespace h2d;

int main( int argc, const char** argv )
int main( int, const char** )
{
auto nbim = 30; // nb images
auto Hdraw = Homogr().setScale(20).addTranslation(10,20);

uint8_t g = 100;
auto kx=2.5;
auto ky=0.9;
auto x0 = 4.8;
Expand Down
7 changes: 1 addition & 6 deletions misc/showcase/showcase6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@
using namespace h2d;
using namespace h2d::img;

int main( int argc, const char** argv )
int main( int, const char** )
{
auto nbim = 25; // nb images
auto Hdraw = Homogr().setScale(30).addTranslation(10,10);

auto r_w0 = 2;
auto r_h0 = 1;
auto x0 = 3.;
auto y0 = 1.;
auto k=1.8;
uint8_t g = 100;

Point2d p1( 2, 4 );
Point2d p2( 6, 5 );
Expand All @@ -32,7 +28,6 @@ int main( int argc, const char** argv )
auto angle_r = angle * M_PI / 180.;
auto x1 = std::cos(angle_r)*k;
auto y1 = std::sin(angle_r)*k;
auto r_w = r_w0 + std::sin( 2.*M_PI*i/nbim );

Point2d p0( x1+x0, y1+x0);
std::vector<Point2d> v1{ p1, p2, p0 };
Expand Down
2 changes: 1 addition & 1 deletion misc/showcase/showcase7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

using namespace h2d;

int main( int argc, const char** argv )
int main( int, const char** )
{
auto n = 25; // nb images
Circle cir( 3. );
Expand Down
2 changes: 1 addition & 1 deletion misc/showcase/showcase7b.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

using namespace h2d;

int main( int argc, const char** argv )
int main( int, const char** )
{
auto n = 25; // nb images
Circle cir( 100,100,15 );
Expand Down
2 changes: 1 addition & 1 deletion misc/showcase/showcase7c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void draw_intersect( const Segment& seg, const T& p )
pt.draw( im, img::DrawParams().setPointStyle( img::PtStyle::Dot ) );
}

int main( int argc, const char** argv )
int main( int, const char** )
{
auto n = 35; // nb images
FRect rect(35,30,110,90);
Expand Down
2 changes: 1 addition & 1 deletion misc/showcase/showcase7d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void draw_object( const Ellipse& ell, const T& p, img::DrawParams& dp )
p.draw( im, dp );
}

int main( int argc, const char** argv )
int main( int, const char** )
{
auto n = 25; // nb images

Expand Down
2 changes: 1 addition & 1 deletion misc/showcase/showcase8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

using namespace h2d;

int main( int argc, const char** argv )
int main( int, const char** )
{
auto nbim = 25; // nb images
auto Hdraw = Homogr().addTranslation(3,2).addScale(40);
Expand Down
2 changes: 1 addition & 1 deletion misc/showcase/showcase9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using namespace h2d;
using namespace h2d::img;

int main( int argc, const char** argv )
int main( int, const char** )
{
auto nbim = 25; // nb images
auto rad_0 = 20;
Expand Down

0 comments on commit 75c513f

Please sign in to comment.