-
Notifications
You must be signed in to change notification settings - Fork 10
/
imagesource_segmentmask.cpp
123 lines (102 loc) · 2.09 KB
/
imagesource_segmentmask.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* imagesource_segmentmask.cpp
* Supports Random Access
*
* Copyright (c) 2005 by Alastair M. Robinson
* Distributed under the terms of the GNU General Public License -
* see the file named "COPYING" for more details.
*
*
*/
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "imagesource_segmentmask.h"
#include "circlemontage.h"
using namespace std;
ImageSource_SegmentMask::~ImageSource_SegmentMask()
{
if(segment)
delete segment;
}
ISDataType *ImageSource_SegmentMask::GetRow(int row)
{
ISDataType *dst;
if(currentrow==row)
return(rowbuffer);
dst=rowbuffer;
float t1=segment->t1;
float t2=segment->t2;
float overlap=segment->overlap;
int dy=row-segment->yo;
if(fade)
{
for(int x=0;x<width;++x)
{
int dx=x-segment->xo;
int dd=int(sqrt(float(dx*dx+dy*dy)));
if((dd<segment->radius) && (dd>=segment->innerradius))
{
float t=(atan2f(dx,-dy)*360)/(2*M_PI);
if(t1>0.0 && t<0.0)
t+=360.0;
if(t>=t1 && t<=t2)
{
if(t<(t1+overlap*2))
{
*dst++=IS_SAMPLEMAX-ISDataType(IS_SAMPLEMAX*(t1-t)/(overlap*2));
}
else if(t>(t2-overlap*2))
{
*dst++=IS_SAMPLEMAX-ISDataType(IS_SAMPLEMAX*(t-t2)/(overlap*2));
}
else
*dst++=IS_SAMPLEMAX;
}
else
*dst++=0;
}
else
{
*dst++=0;
}
}
}
else
{
for(int x=0;x<width;++x)
{
int dx=x-segment->xo;
int dd=int(sqrt(float(dx*dx+dy*dy)));
if((dd<segment->radius) && (dd>=segment->innerradius))
{
int t=int((atan2f(dx,-dy)*360)/(2*M_PI));
if(t1>0 && t<0)
t+=360;
if(t>=t1 && t<=t2)
{
*dst++=IS_SAMPLEMAX;
}
else
*dst++=0;
}
else
{
*dst++=0;
}
}
}
currentrow=row;
return(rowbuffer);
}
ImageSource_SegmentMask::ImageSource_SegmentMask(CMSegment *seg,bool fade)
: ImageSource(), segment(seg), fade(fade)
{
type=IS_TYPE_GREY;
samplesperpixel=1;
width=seg->w;
height=seg->h;
MakeRowBuffer();
randomaccess=true;
}