comparison UnitTestsSources/ImageProcessingTests.cpp @ 3258:6f652c7bfc85

ImageProcessing::FillPolygon
author Alain Mazy <alain@mazy.be>
date Mon, 18 Feb 2019 18:43:40 +0100
parents 4e43e67f8ecf
children 345f86fd1ac3
comparison
equal deleted inserted replaced
3257:5d1f998b0b18 3258:6f652c7bfc85
178 { 178 {
179 ImageAccessor& image = this->GetImage(); 179 ImageAccessor& image = this->GetImage();
180 180
181 memset(image.GetBuffer(), 128, image.GetHeight() * image.GetWidth()); 181 memset(image.GetBuffer(), 128, image.GetHeight() * image.GetWidth());
182 182
183 unsigned int c = 0; 183 float c = 0.0f;
184 for (unsigned int y = 0; y < image.GetHeight(); y++) 184 for (unsigned int y = 0; y < image.GetHeight(); y++)
185 { 185 {
186 for (unsigned int x = 0; x < image.GetWidth(); x++, c++) 186 for (unsigned int x = 0; x < image.GetWidth(); x++, c++)
187 { 187 {
188 TestFixture::ImageTraits::SetFloatPixel(image, c, x, y); 188 TestFixture::ImageTraits::SetFloatPixel(image, c, x, y);
189 } 189 }
190 } 190 }
191 191
192 c = 0;
193 for (unsigned int y = 0; y < image.GetHeight(); y++) 192 for (unsigned int y = 0; y < image.GetHeight(); y++)
194 { 193 {
195 for (unsigned int x = 0; x < image.GetWidth(); x++, c++) 194 for (unsigned int x = 0; x < image.GetWidth(); x++, c++)
196 { 195 {
197 ASSERT_FLOAT_EQ(c, TestFixture::ImageTraits::GetFloatPixel(image, x, y)); 196 ASSERT_FLOAT_EQ(c, TestFixture::ImageTraits::GetFloatPixel(image, x, y));
198 } 197 }
199 } 198 }
200 } 199 }
200
201 TYPED_TEST(TestIntegerImageTraits, FillPolygon)
202 {
203 ImageAccessor& image = this->GetImage();
204
205 ImageProcessing::Set(image, 128);
206
207 // draw a triangle
208 std::vector<ImageProcessing::ImagePoint> points;
209 points.push_back(ImageProcessing::ImagePoint(1,1));
210 points.push_back(ImageProcessing::ImagePoint(1,5));
211 points.push_back(ImageProcessing::ImagePoint(5,5));
212
213 Orthanc::ImageProcessing::FillPolygon(image, points, 255);
214
215 // outside polygon
216 ASSERT_FLOAT_EQ(128, TestFixture::ImageTraits::GetFloatPixel(image, 0, 0));
217 ASSERT_FLOAT_EQ(128, TestFixture::ImageTraits::GetFloatPixel(image, 0, 6));
218 ASSERT_FLOAT_EQ(128, TestFixture::ImageTraits::GetFloatPixel(image, 6, 6));
219 ASSERT_FLOAT_EQ(128, TestFixture::ImageTraits::GetFloatPixel(image, 6, 0));
220
221 // inside polygon (note: we don't test too close from the edges since the current algo is taking some margin from the edges and might be improved in that sense)
222 ASSERT_FLOAT_EQ(255, TestFixture::ImageTraits::GetFloatPixel(image, 1, 2));
223 ASSERT_FLOAT_EQ(255, TestFixture::ImageTraits::GetFloatPixel(image, 2, 4));
224 }