Exemplo n.º 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;
			}

}
Exemplo n.º 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 );
}
Exemplo n.º 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++;
}
Exemplo n.º 4
0
void Init( HWND hWnd )				// Note: init gets called before window is created so need to pass hWnd
{
	int i;
	Contour *contour;
	Point *p;
														// debugging variables/flags
	totalTime1 = 0;
	nTime1 = 0;
	totalTime2 = 0;
	nTime2 = 0;
	totalTime3 = 0;
	nTime3 = 0;
	debugit = 0;
	debugLogFile = INVALID_HANDLE_VALUE;				// disable debug logging
	
	srand(GetTickCount());			// randomize seed of random number generator

	appWnd = hWnd;					// remember main Window handle
	WindowWasMaximized = false;

	InitCommonControls();			// common controls used: PropertySheet, ListView, ImageList, HotKey, ColorDialog
	
	AbortRender = false;
	AbortThumbs = false;
	AbortObject = false;
	AbortDistances = false;
	Abort3D = false;
	hRenderThread = NULL;			// clear thread handles while not active
	hThumbsThread = NULL;
	hObjectListThread = NULL;
	hDistanceListThread = NULL;
	hGenerate3DThread = NULL;

	strcpy(BaseName,"aSeries\0");
	strcpy(FindString,"\0");
	ExpandEnvironmentStrings("%HOMEPATH%",WorkingPath,MAX_PATH);
	SkipAllMissing = false;
	HideAllDomains = false;
	CurrSeries = NULL;
	CurrSectionsInfo = NULL;
	CurrSection = NULL;
	CurrView = NULL;
	PrevSection = NULL;
	PrevView = NULL;
	DomainSection = NULL;
	DomainView = NULL;
	FrontView = NULL;
	BackView = NULL;
	BlendView = NULL;
	CurrContour = NULL;
	CurrDomain = NULL;
	ClipboardTransform = NULL;

	toolbarWindow = NULL;								// tool window variables
	ToolButtons = NULL;									// buttons are created when window is created
	highlightedToolButton = NULL;						// none highlighted initially
	CurrentTool = ARROW_TOOL;
	RToolActive = false;
	LToolActive = false;
	ToolContour = NULL;
	EditContour = NULL;
	statusbarWindow = NULL;
	dragPen = NULL;

	CmRestoreToolbar();									// create toolbar and statusbar windows...
	CmStatusBar();

	openGLWindow = NULL;								// ...but not openGL...
	openGL_LToolActive = false;
	openGL_RToolActive = false;
	openGL_ortho = false;
	openGLanimated = true;
	CurrScene = NULL;
	distanceWindow = NULL;
	zTraceWindow = NULL;
	objectWindow = NULL;
	CurrObjects = NULL;
	InterObjectDistances = NULL;
	sectionWindow = NULL;								// ...or other doubleing windows or dialogs
	thumbnailWindow = NULL;
	ThumbButtons = NULL;
	PassbackButtons = NULL;
	domainWindow = NULL;
	traceWindow = NULL;
	CurrContours = NULL;
	paletteWindow = NULL;
	PaletteButtons = NULL;
	DefaultPaletteButtons = NULL;
	highlightedPaletteButton = NULL;
	PaintingViews = false;
	ImagePixelSize = 0.00254;							// more dialog elements defaults
	ImageBrightness = 0.0;
	ImageContrast = 1.0;
	RenderWindow = false;
	RenderJPEG = false;
	RenderFill = false;
	RenderTraces = false;
	JPEGquality = 80;
	CopyFiles = true;									// initialize custom colors (will load these later from Series)
	for (i=0; i<16; i++)
		CustomColors[i] = RGB( 0, 0, 0 );
	GlobalId = 0;
	Precision = 6;
	LastOptionTab = 0;
	CalibrationScope = APPLY_TRACES;
														// use fullsize buttons at 120 dpi
	appDC = GetDC( appWnd );
	ButtonSize = BUTTON_SIZE*GetDeviceCaps( appDC, LOGPIXELSX )/120;
	ReleaseDC( appWnd, appDC );

	ScrollOccurred = false;
	Scrolling = false;
	AutoSimplify = true;
	AutoShrinkBack = false;
	UsePrecisionCursor = false;
	AutoTrace = 0;
	AutoAdjustThreshold = false;
	
	SimplifyResolution = -ImagePixelSize;
	ApplyZOffset3D = false;
	OffsetZTrace1 = NULL;
	OffsetZTrace2 = NULL;
														// load lock/unlock bitmaps for status bar
	lockBitmap = LoadBitmap(appInstance, "LockBitmap");
	unlockBitmap = LoadBitmap(appInstance, "UnlockBitmap");

														// keyboard movement options
	LastAdjustment = NULL;
	Recording = NULL;
	UseDeformKeys = false;
												// set strings for list row limits to allow all names
	strcpy(limitSectionList,"*\0");
	strcpy(limitDomainList,"*\0");
	strcpy(limitTraceList,"*\0");
	strcpy(limitObjectList,"*\0");
	strcpy(limitLeftDistanceList,"*\0");
	strcpy(limitRightDistanceList,"*\0");
	strcpy(limitZTraceList,"*\0");

	PointContours = new Contours();				// set pixel offset values for stamp tool contours
	contour = new Contour();
	PointContours->Add( contour );
	sprintf(contour->name,"a$+");						// orange
	contour->mode = R2_COPYPEN;
	contour->simplified = true;
	contour->border = Color( 1.0, 0.5, 0.0 );
	contour->fill = Color( 1.0, 0.5, 0.0 );
	contour->points = new Points();						// hexagonal shape
	int hexagon[] = { -3, 1, -3, -1, -1, -3, 1, -3, 3, -1, 3, 1, 1, 3, -1, 3 };
	for ( i=0; i<16; i=i+2 )
		{
		p = new Point((double)hexagon[i],(double)hexagon[i+1],0.0);
		contour->points->Add(p);
		}

	contour = new Contour();
	PointContours->Add( contour );
	sprintf(contour->name,"b$+");						// purple
	contour->mode = R2_COPYPEN;
	contour->simplified = true;
	contour->border = Color( 0.5, 0.0, 1.0 );
	contour->fill = Color( 0.5, 0.0, 1.0 );
	contour->points = new Points();						// 8-star shape
	int star[] = { -4, 4, -1, 2, 0, 5, 1, 2, 4, 4, 2, 1, 5, 0, 2, -1, 4, -4, 1, -2, 0, -5, -1, -2, -4, -4, -2, -1, -5, 0, -2, 1 };
	for ( i=0; i<32; i=i+2 )
		{
		p = new Point((double)star[i],(double)star[i+1],0.0);
		contour->points->Add(p);
		}
	contour->Reverse();									// make for clockwise creation

	contour = new Contour();
	PointContours->Add( contour );
	sprintf(contour->name,"pink$+");					// pink
	contour->mode = -R2_COPYPEN;
	contour->simplified = true;
	contour->border = Color( 1.0, 0.0, 0.5 );
	contour->fill = Color( 1.0, 0.0, 0.5 );
	contour->points = new Points();						// trianglar shape
	int triangle[] = { -6, -6, 6, -6, 0, 5 };
	for ( i=0; i<6; i=i+2 )
		{
		p = new Point((double)triangle[i],(double)triangle[i+1],0.0);
		contour->points->Add(p);
		}

	contour = new Contour();
	PointContours->Add( contour );
	sprintf(contour->name,"X$+");
	contour->mode = -R2_COPYPEN;
	contour->simplified = true;
	contour->border = Color( 1.0, 0.0, 0.0 );			// red
	contour->fill = Color( 1.0, 0.0, 0.0 );
	contour->points = new Points();						// x shape
	int x[] = { -7, 7, -2, 0, -7, -7, -4, -7, 0, -1, 4, -7, 7, -7, 2, 0, 7, 7, 4, 7, 0, 1, -4, 7 };
	for ( i=0; i<24; i=i+2 )
		{
		p = new Point((double)x[i],(double)x[i+1],0.0);
		contour->points->Add(p);
		}

	contour = new Contour();
	PointContours->Add( contour );
	sprintf(contour->name,"yellow$+");					// yellow
	contour->mode = -R2_COPYPEN;
	contour->simplified = true;
	contour->border = Color( 1.0, 1.0, 0.0 );
	contour->fill = Color( 1.0, 1.0, 0.0 );
	contour->points = new Points();						// square annulus shape
	int square[] = { -4, 4, -5, 5, 5, 5, 5, -5, -5, -5, -5, 4, -4, 3, -4, -4, 4, -4, 4, 4 };
	for ( i=0; i<20; i=i+2 )
		{
		p = new Point((double)square[i],(double)square[i+1],0.0);
		contour->points->Add(p);
		}
	contour->Reverse();									// make for clockwise creation
	contour->Scale( 2.0 );								// double in size

	contour = new Contour();
	PointContours->Add( contour );
	sprintf(contour->name,"blue$+");					// blue
	contour->mode = R2_MASKPEN;
	contour->simplified = true;
	contour->border = Color( 0.0, 0.0, 1.0 );
	contour->fill = Color( 0.0, 0.0, 1.0 );
	contour->points = new Points();						// diamond shape
	int diamond[] = { 0, 7, -7, 0, 0, -7, 7, 0 };
	for ( i=0; i<8; i=i+2 )
		{
		p = new Point((double)diamond[i],(double)diamond[i+1],0.0);
		contour->points->Add(p);
		}

	contour = new Contour();
	PointContours->Add( contour );
	sprintf(contour->name,"magenta$+");
	contour->mode = R2_MASKPEN;
	contour->simplified = true;
	contour->border = Color( 1.0, 0.0, 1.0 );			// magenta
	contour->fill = Color( 1.0, 0.0, 1.0 );
	contour->points = new Points();						// larger hexagonal shape
	for ( i=0; i<16; i=i+2 )
		{
		p = new Point((double)hexagon[i],(double)hexagon[i+1],0.0);
		contour->points->Add(p);
		}
	contour->Scale( 2.0 );								// double in size

	contour = new Contour();
	PointContours->Add( contour );
	sprintf(contour->name,"red$+");						// red
	contour->mode = R2_MASKPEN;
	contour->simplified = true;
	contour->border = Color( 1.0, 0.0, 0.0 );
	contour->fill = Color( 1.0, 0.0, 0.0 );
	contour->points = new Points();						// curved arrow shape
	int curved[] = { -1, -4, -4, -2, -2, -2, -2, 0, -1, 2, 1, 4, 2, 2, 4, 1, 1, 0, 0, -1, 0, -2, 2, -2 };
	for ( i=0; i<24; i=i+2 )
		{
		p = new Point((double)curved[i],(double)curved[i+1],0.0);
		contour->points->Add(p);
		}
	contour->Reverse();									// make for clockwise creation
	contour->Scale( 3.0 );								// triple in size

	contour = new Contour();
	PointContours->Add( contour );
	sprintf(contour->name,"green$+");
	contour->mode = R2_MASKPEN;
	contour->simplified = true;
	contour->border = Color( 0.0, 1.0, 0.0 );			// yellow
	contour->fill = Color( 0.0, 1.0, 0.0 );
	contour->points = new Points();						// large cross shape
	int cross[] = { -3, 1, -3, -1, -1, -1, -1, -3, 1, -3, 1, -1, 3, -1, 3, 1, 1, 1, 1, 3, -1, 3, -1, 1 };
	for ( i=0; i<24; i=i+2 )
		{
		p = new Point((double)cross[i],(double)cross[i+1],0.0);
		contour->points->Add(p);
		}
	contour->Scale( 4.0 );								// double in size

	contour = new Contour();
	PointContours->Add( contour );
	sprintf(contour->name,"cyan$+");
	contour->mode = R2_MASKPEN;
	contour->simplified = true;
	contour->border = Color( 0.0, 1.0, 1.0 );			// green
	contour->fill = Color( 0.0, 1.0, 1.0 );
	contour->points = new Points();						// large arrow shape
	int arrow[] = { 0, 3, 1, 2, -3, -2, -2, -3, 2, 1, 3, 0, 3, 3 };
	for ( i=0; i<14; i=i+2 )
		{
		p = new Point((double)arrow[i],(double)arrow[i+1],0.0);
		contour->points->Add(p);
		}
	contour->Scale( 4.0 );								// quadruple in size

														// finally setup stamp tool contour and cursor
	StampContour = new Contour( *(PointContours->first) );
	StampCursor = MakeStampCursor( StampContour );
}