Tried to implement a new of drawing conics. Unfortunately it doesn't work for some cases: , ImageDraw
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <Base/Image/Image.hh>
#include <Base/Image/ImageIO.hh>
#include <Base/ImageUtils/ImageDraw.hh>
#include <Base/Geometry/HomgPoint2D.hh>
#include <Base/Geometry/HomgPoint3D.hh>
#include <Geometry/RMatrix.hh>
#include <Geometry/Conic2D.hh>
using namespace BIAS;
using namespace std;
return p1;
}
else {
return p2;
}
}
bool ConicGetStartPoint(
const Conic2D &conic,
unsigned int imageWidth, unsigned int imageHeight,
p.Homogenize();
p1.Homogenize();
p2.Homogenize();
register int initialSign;
int initialSign1, initialSign2;
double dist;
p1[1] = 0;
p2[1] = imageHeight - 1;
if (dist > 0.0)
initialSign1 = 1;
else if (dist < 0.0)
initialSign1 = -1;
else
initialSign1 = 0;
if (dist > 0.0)
initialSign2 = 1;
else if (dist < 0.0)
initialSign2 = -1;
else
initialSign2 = 0;
for (register unsigned int x = 1; x < imageWidth; x++) {
p1[0] = x;
if (dist < 0.0 && initialSign1 > 0) {
startPoint = ConicMinDist(conic,
HomgPoint2D(x - 1, 0), p1);
return true;
}
if (dist > 0.0 && initialSign1 < 0) {
startPoint = ConicMinDist(conic,
HomgPoint2D(x - 1, 0), p1);
return true;
}
if (dist == 0.0) {
startPoint = ConicMinDist(conic,
HomgPoint2D(x - 1, 0), p1);
return true;
}
p2[0] = x;
if (dist < 0.0 && initialSign2 > 0) {
startPoint = ConicMinDist(conic,
HomgPoint2D(x - 1, imageHeight - 1), p2);
return true;
}
if (dist > 0.0 && initialSign2 < 0) {
startPoint = ConicMinDist(conic,
HomgPoint2D(x - 1, imageHeight - 1), p2);
return true;
}
if (dist == 0.0) {
startPoint = ConicMinDist(conic,
HomgPoint2D(x - 1, imageHeight - 1), p2);
return true;
}
}
p1[0] = 0;
p2[0] = imageWidth - 1;
if (dist > 0.0)
initialSign1 = 1;
else if (dist < 0.0)
initialSign1 = -1;
else
initialSign1 = 0;
if (dist > 0.0)
initialSign2 = 1;
else if (dist < 0.0)
initialSign2 = -1;
else
initialSign2 = 0;
for (register unsigned int y = 1; y < imageHeight; y++) {
p1[1] = y;
if (dist < 0.0 && initialSign1 > 0) {
startPoint = ConicMinDist(conic,
HomgPoint2D(0, y), p1);
return true;
}
if (dist > 0.0 && initialSign1 < 0) {
startPoint = ConicMinDist(conic,
HomgPoint2D(0, y), p1);
return true;
}
if (dist == 0.0) {
startPoint = ConicMinDist(conic,
HomgPoint2D(0, y), p1);
return true;
}
p2[1] = y;
if (dist < 0.0 && initialSign2 > 0) {
startPoint = ConicMinDist(conic,
HomgPoint2D(imageWidth - 1, y), p2);
return true;
}
if (dist > 0.0 && initialSign2 < 0) {
startPoint = ConicMinDist(conic,
HomgPoint2D(imageWidth - 1, y), p2);
return true;
}
if (dist == 0.0) {
startPoint = ConicMinDist(conic,
HomgPoint2D(imageWidth - 1, y), p2);
return true;
}
}
for (register unsigned int y = 0; y < imageHeight; y++) {
p[0] = -1;
p[1] = y;
if (dist > 0.0)
initialSign = 1;
else if (dist < 0.0)
initialSign = -1;
else
initialSign = 0;
for (register unsigned int x = 0; x < imageWidth; x++) {
p[0] = x;
p[1] = y;
if (dist < 0.0 && initialSign > 0) {
startPoint = ConicMinDist(conic,
HomgPoint2D(x - 1, y), p);
return true;
}
if (dist > 0.0 && initialSign < 0) {
startPoint = ConicMinDist(conic,
HomgPoint2D(x - 1, y), p);
return true;
}
if (dist == 0.0) {
startPoint = ConicMinDist(conic,
HomgPoint2D(x - 1, y), p);
return true;
}
}
}
for (register unsigned int x = 0; x < imageWidth; x++) {
p[0] = x;
p[1] = -1;
if (dist > 0.0)
initialSign = 1;
else if (dist < 0.0)
initialSign = -1;
else
initialSign = 0 ;
for (register unsigned int y = 0; y < imageWidth; y++) {
p[0] = x;
p[1] = y;
if (dist < 0.0 && initialSign > 0) {
startPoint = ConicMinDist(conic,
HomgPoint2D(x, y - 1), p);
return true;
}
if (dist > 0.0 && initialSign < 0) {
startPoint = ConicMinDist(conic,
HomgPoint2D(x, y - 1), p);
return true;
}
if (dist == 0.0) {
startPoint = ConicMinDist(conic,
HomgPoint2D(x, y - 1), p);
return true;
}
}
}
return false;
}
const unsigned int x = (unsigned int)rint(p[0]);
const unsigned int y = (unsigned int)rint(p[1]);
pImageData[offset + c] = 255;
}
}
bool ConicGetNextPoint(
const Conic2D &conic,
double distP, distQ;
bool pUnvisited, qUnvisited;
cout << "getting next point" << endl;
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
p[0] = curPoint[0] + x;
p[1] = curPoint[1] + y;
if (x < 1) {
q[0] = p[0] + 1;
q[1] = p[1];
pUnvisited =
pVisitedPoints[(unsigned int)p[0]][(unsigned int)p[1]] == 0;
qUnvisited =
pVisitedPoints[(unsigned int)q[0]][(unsigned int)q[1]] == 0;
if (distP == 0.0 && pUnvisited) {
nextPoint = p;
return true;
}
if (distQ == 0.0 && qUnvisited) {
nextPoint = q;
return true;
}
if ((distP < 0.0 && distQ > 0.0) || (distP > 0.0 && distQ < 0.0)) {
if (pUnvisited && qUnvisited) {
nextPoint = ConicMinDist(conic, p, q);
return true;
}
}
}
if (y < 1) {
q[0] = p[0];
q[1] = p[1] + 1;
pUnvisited =
pVisitedPoints[(unsigned int)p[0]][(unsigned int)p[1]] == 0;
qUnvisited =
pVisitedPoints[(unsigned int)q[0]][(unsigned int)q[1]] == 0;
if (distP == 0.0 && pUnvisited) {
nextPoint = p;
return true;
}
if (distQ == 0.0 && qUnvisited) {
nextPoint = q;
return true;
}
if ((distP < 0.0 && distQ > 0.0) || (distP > 0.0 && distQ < 0.0)) {
if (pUnvisited && qUnvisited) {
nextPoint = ConicMinDist(conic, p, q);
return true;
}
}
}
}
}
return false;
}
return 1;
}
cout << endl << "got start point " << curPoint << endl;
ConicShadePixel(image, curPoint);
pVisitedPoints[(unsigned int)curPoint[0]][(unsigned int)curPoint[1]] = 1;
lastPoint = curPoint;
while (ConicGetNextPoint(conic, visitedPoints, lastPoint, curPoint)) {
cout << "got next point " << curPoint << endl;
ConicShadePixel(image, curPoint);
pVisitedPoints[(unsigned int)curPoint[0]][(unsigned int)curPoint[1]] = 1;
lastPoint = curPoint;
}
return 0;
}
int main(int argc, char** argv) {
DrawConic(image, conic);
return 0;
}