Example #1
0
void ViewPort::DrawEditContour( double pixel_size, double offset_x, double offset_y )
{
	HPEN pen, oldpen;
	HBRUSH brush, oldbrush;
	LOGBRUSH lbrush;
	int oldmode, i, x, y, numpts;
	Contour *c;
	Point *p;
	POINT *lpPoints;

	if ( EditContour && viewDC )
		if ( EditContour->points )
			{
			c = new Contour( *EditContour );				// copy the contour
			
			c->Shift( -offset_x, -offset_y );				// shift into view
			c->Scale( 1.0/pixel_size );						// scale to view's pixels
				
			numpts = c->points->Number();
			lpPoints = new POINT[ numpts ];					// create Window POINT array for drawing

			i = 0;
			p = c->points->first;
			while ( p != NULL )
				{
				lpPoints[i].x = (int)floor(p->x);
				lpPoints[i].y = height - (int)floor(p->y);
				i++;
				p = p->next;
				}
															// create pen for border of object
			pen = CreatePen( PS_DOT, 1, c->border.ref() );
			//pen = CreatePen( PS_SOLID, 1, c->border.ref() );
			oldpen = (HPEN)SelectObject( viewDC, pen );		// set pen into device context

			if ( (c->mode > 0) && c->closed )
				{
				brush = CreateSolidBrush( c->fill.ref() );	// interior will be filled
				oldbrush = (HBRUSH)SelectObject( viewDC, brush );
				SetROP2( viewDC, abs(c->mode) );			// using contour fill mode and color
				Polygon( viewDC, lpPoints, numpts );
				SelectObject( viewDC, oldbrush );			// clean up fill brush
				DeleteObject(brush);
				}

			SelectObject( viewDC, (HBRUSH)GetStockObject(NULL_BRUSH) );	// without coloring interior
			SetROP2( viewDC, R2_COPYPEN );								// draw contour border with pen
			if ( c->closed ) Polygon( viewDC, lpPoints, numpts );
			else Polyline( viewDC, lpPoints, numpts );
			
			SelectObject( viewDC, oldpen );					// clean up pen
			DeleteObject(pen);
			delete[] lpPoints;								// and dynamic memory
			delete c;
			}

}
Example #2
0
HBITMAP MakeContourBitmap( HWND hWnd, Contour *contour )	// Convert pixel offset contour into a bitmap for button
{
	Contour *c;
	Point *p, min, max;
	double fx, fy, size;
	int i, numpts;
	POINT *lpPoints;
	HPEN pen;
	HBRUSH brush;
	HBITMAP canvas, stipple;
	RECT wrect;
	HDC winDC, canvasDC;

	winDC = GetDC( hWnd );							// create bitmap for contour image					
	canvas = CreateCompatibleBitmap( winDC, ButtonSize, ButtonSize );
	canvasDC = CreateCompatibleDC( winDC );			// create DC for drawing
	SelectObject( canvasDC, canvas );				// select bitmap in DC for drawing
	ReleaseDC( hWnd, winDC );						// done with display DC for now

	GetClientRect( hWnd, &wrect );					// paint background
	stipple = LoadBitmap(appInstance, "StippleBitmap");
	brush = CreatePatternBrush( stipple );
	FillRect( canvasDC, &wrect, brush );
	DeleteObject( brush );
	DeleteObject( stipple );
	
	c = new Contour( *contour );
	c->YInvert( 0.0 );								// flip y coord. offsets
	c->Extent( &min, &max );						// how big is it?
	fx = max.x - min.x;
	fy = max.y - min.y;								// if it's bigger than the bitmap
	if ( fy > fx ) fx = fy;							// squeeze it down into bitmap size
	size = ButtonSize - 4;
	if ( fx > size ) c->Scale( (double)size/(double)fx );
	c->Shift( ButtonSize/2, ButtonSize/2 );	// center on bitmap

	numpts = c->points->Number();
	lpPoints = new POINT[ numpts ];					// create Window POINT array for drawing
	i = 0;
	p = c->points->first;							// translate shrunken contour into POINTS
	while ( p != NULL )
		{
		lpPoints[i].x = (int)floor(p->x);
		lpPoints[i].y = (int)floor(p->y);
		i++;
		p = p->next;
		}
													// create pen for border of object
	pen = CreatePen( PS_SOLID, 1, c->border.ref() );
	SelectObject( canvasDC, pen );					// set pen into device context
	brush = CreateSolidBrush( c->fill.ref() );		// interior will be filled
	SelectObject( canvasDC, brush );
	SetROP2( canvasDC, abs(c->mode) );				// using contour fill mode and color
	Polygon( canvasDC, lpPoints, numpts );

	SelectObject( canvasDC, (HBRUSH)GetStockObject(NULL_BRUSH) );
	DeleteObject(brush);							// clean up fill brush

	SetROP2( canvasDC, R2_COPYPEN );				// draw contour border with pen only
	Polygon( canvasDC, lpPoints, numpts );

	DeleteObject(pen);								// clean up pen
	delete[] lpPoints;								// and dynamic memory
	DeleteDC( canvasDC );

	return( canvas );
}
Example #3
0
void ViewPort::RenderImages( RECT region, double pixel_size, double offset_x, double offset_y, bool use_proxy )
{
	Transform *transform;									// render image onto view using pixel_size
	Point *p, min, max;
	Contour *domain;
	RECT r, labeled;
	double x, y, area;
	int index, i;
	char txt[128];
	Image_Ptr images[MAX_DOMAINS];						// number of domains is limited by 8bit mask size
	Nform_Ptr nforms[MAX_DOMAINS];
	POINT mins[MAX_DOMAINS], maxs[MAX_DOMAINS];
// begin debug logging...
	DWORD byteswritten;
	char line[MAX_PATH];
	if ( debugLogFile != INVALID_HANDLE_VALUE )
		{
		sprintf(line,"Entered ViewPort::RenderImages\r\n");
		WriteFile(debugLogFile, line, strlen(line), &byteswritten, NULL);
		}
// ...end debug logging
startTime3 = GetTickCount();
															// check for valid render region
	if ( (region.right - region.left) < 0 ) return;
	if ( (region.bottom - region.top) < 0 ) return;
															// limit render region to view pixels
	if ( region.left < 0 ) r.left = 0; else r.left = region.left;
	if ( region.right >= width ) r.right = width-1; else r.right = region.right;
	if ( region.top < 0 ) r.top = 0; else r.top = region.top;
	if ( region.bottom >= height ) r.bottom = height-1; else r.bottom = region.bottom;
	
	ClearImages( r );								// clear the region to all zeros before rendering
	
	for (index=0; index < MAX_DOMAINS; index++)		// clear the image and nform pointer arrays
		{
		images[index] = NULL;
		nforms[index] = NULL;
		}

	if ( section->transforms )
		{											// FIRST PASS... Create index mask for images on view
		index = 0;													// count every domain in section with index
		transform = section->transforms->first;						// render in order, back to front
		while ( transform && (index < MAX_DOMAINS) )
			{			
			if ( transform->image ) 								// do only if image is present and not hidden
				{
				if ( transform->domain && !transform->domain->hidden )
					{												// use domain boundary to define render area...
					index++;										
					domain = new Contour( *(transform->domain) );	// create a copy of domain
					domain->Scale( transform->image->mag );			// go from pixels to units
					domain->InvNform( transform->nform );			// transform into section
					domain->Shift( -offset_x, -offset_y );			// shift from view offset			
					labeled = view->Mask( domain, pixel_size, index, r );	// label pixels for rendering
					if ( labeled.left <= labeled.right )			// only use if some interior pixels were set
						{									
						images[index] = transform->image;			// store ptr to image for later rendering step
						nforms[index] = transform->nform;
						mins[index].x = labeled.left; mins[index].y = labeled.top;
						maxs[index].x = labeled.right; maxs[index].y = labeled.bottom;
						}
					delete domain;									// delete copy of domain
					}
				}
			transform = transform->next;				// do next transform in list
			}

		while ( index > 0 )							// SECOND PASS... render each indexed subregion from image sources
			{										
			view->MaskXform( images[index], nforms[index], index, mins[index], maxs[index],
																	pixel_size, offset_x, offset_y, use_proxy );
			index--;
			}
		}
totalTime3 += GetTickCount() - startTime3;	// DEBUGGING
nTime3++;
}