Files
Work/meshwrp/convex.cpp
2024-08-07 09:16:27 -04:00

55 lines
1.3 KiB
C++

#include <meshwrp/main.hpp>
#include <meshwrp/convex.hpp>
#include <meshwrp/image.hpp>
#include <common/math.hpp>
#include <common/guiwnd.hpp>
Convex::Convex()
: mWidth(0), mHeight(0), mxHalf(0), myHalf(0)
{
}
Convex::~Convex()
{
}
Image Convex::performConvex(Image &srcImage,GUIWindow &window)
{
RGB888 rgb888;
Image dstImage;
POINT tempPoint;
double scaleFactor;
double tempFactor;
mWidth=srcImage.width();
mHeight=srcImage.height();
mxHalf=mWidth/2;
myHalf=mHeight/2;
dstImage.newImage(mWidth,mHeight,window);
for(int y=0;y<mHeight;y++)
{
for(int x=0;x<mWidth;x++)
{
setPoint(x,y,tempPoint);
cartesianPoint(tempPoint);
tempFactor=::sqrt(((LONG)tempPoint.x*(LONG)tempPoint.x)+((LONG)tempPoint.y*(LONG)tempPoint.y));
tempFactor*=Math::piOver180();
if(tempFactor)scaleFactor=(::tan(::atan(tempFactor)/2.00))/tempFactor;
else scaleFactor=0.00;
scaleFactor*=2;
tempFactor=scaleFactor*(double)tempPoint.x;
tempFactor+=(tempFactor<0?-.5:.5);
tempPoint.x=tempFactor;
tempFactor=scaleFactor*(double)tempPoint.y;
tempFactor+=(tempFactor<0?-.5:.5);
tempPoint.y=tempFactor;
imagePoint(tempPoint);
if(tempPoint.x>=mWidth)continue;
if(tempPoint.y>=mHeight)continue;
srcImage.getAt(y,x,rgb888);
dstImage.setAt(tempPoint.y,tempPoint.x,rgb888);
}
}
return dstImage;
}