Initial
This commit is contained in:
54
meshwrp/convex.cpp
Normal file
54
meshwrp/convex.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user