Exemple #1
0
void MainWindow::contractUp()
{
    Imath::V3i sizeInc(0,0,0);
    switch (m_glModelWidget->currentAxis())
    {
        case X_AXIS: sizeInc.x -= 1; break;
        case Y_AXIS: sizeInc.y -= 1; break;
        case Z_AXIS: sizeInc.z -= 1; break;
    }
    m_glModelWidget->resizeAndShiftVoxelGrid(sizeInc, Imath::V3i(0,0,0));
}
Exemple #2
0
void MainWindow::extendDown()
{
    Imath::V3i shift(0,0,0);
    Imath::V3i sizeInc(0,0,0);
    switch (m_glModelWidget->currentAxis())
    {
        case X_AXIS: sizeInc.x += 1; shift.x += 1; break;
        case Y_AXIS: sizeInc.y += 1; shift.y += 1; break;
        case Z_AXIS: sizeInc.z += 1; shift.z += 1; break;
    }
    m_glModelWidget->resizeAndShiftVoxelGrid(sizeInc, shift);
}
// protected:
BOOL COXSplashWnd::BuildRegion(POINT ptStart)
	// --- In      : ptStart, the starting point to search for region boundary
	// --- Out     :
	// --- Returns : TRUE if successful; FALSE otherwise
	// --- Effect  : calculate the region to be visible in a bitmap
{
	CArray<CPoint, CPoint&> vertexs;
	CPoint ptMax(0,0);
	CPoint pt0(0,0);
	CPoint pt1(0,0);
	CPoint pt(0,0);
	CPoint ptPrev(0,0);
	CSize sizeInc(0,0);
	int i = 0;
	int iFirst = 0;
	int iLast = 0;
	int iPrev = 0;

	// move directions: index (xInc, yInc) alternate_index
	//        0 (-1,-1) 8    1 ( 0,-1) 9    2 ( 1,-1) 10
	//		  7 (-1, 0)	15		            3 ( 1, 0) 11
	//		  6 (-1, 1) 14   5 ( 0, 1) 13   4 ( 1, 1) 12
	const int xd[] = {-1,0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1};
	const int yd[] = {-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1,1,1,0};
	const int nextdir[] = {6,0,0,2,2,4,4,6,6,0,0,2,2,4,4,6};

	BITMAP bm;
	m_dib.GetBitmapInfo(bm);
	ptMax = CPoint(bm.bmWidth - 1, bm.bmHeight - 1);

	// find a start point that's outside the region
	UNREFERENCED_PARAMETER(ptStart);
	pt0 = CPoint(0,0);
	if (!IsBorder(pt0)) 
		pt0 = CPoint(-1,-1);

	// search diagonally for first point that's within the region
	sizeInc.cx = (pt0.x > (ptMax.x / 2)) ? -1 : 1;
	sizeInc.cy = (pt0.y > (ptMax.y / 2)) ? -1 : 1;
	for (pt1 = pt0 + sizeInc; IsBorder(pt1, FALSE); pt1 += sizeInc)
		;
	pt0 = pt1 - sizeInc;
	
	// if not found after hitting the boundary, search by scan lines
	if (m_dib.GetPixel(pt1) == CLR_INVALID)
	{
		for (pt1.y = 0; pt1.y <= ptMax.y; pt1.y++)
		{
			for (pt1.x = 0; pt1.x <= ptMax.x && IsBorder(pt1); pt1.x++)
				;
			if (pt1.x <= ptMax.x) 
				break;
		}
		if (ptMax.y < pt1.y) 
			return FALSE;
		pt0 = pt1 - CSize(0, 1);
	}

	// now pt1 should be the starting point that's within the region
	// and pt0 should be a neigboring point that's outside the region
	ASSERT(IsBorder(pt0) && !IsBorder(pt1));

	// clockwise find border/region boundary
	for (i = 0; i <= 7; i++)
	{
		pt = pt1 + CSize(xd[i], yd[i]);
		if (!IsBorder(pt)) 
			break;
	}
	if (i == 8) 
		return FALSE;

	// important: assign second point as the start point to prevent
	//			  diagonal circumvent
	pt1 = pt;
	vertexs.Add(pt);
	
	// cycle until the most beginning point is found back again
	do 
	{
		iPrev = i;
		ptPrev = pt;
		iFirst = nextdir[i];
		iLast = iFirst + 6;
		for (i = iFirst; i <= iLast; i++)
		{
			pt = ptPrev + CSize(xd[i], yd[i]);
			if (!IsBorder(pt)) 
				break;
		}
		if (i == iPrev)
		{
			// moving forward on the same direction
			// replace the last point with this new one, so that region
			// definition could be simpler
			vertexs[vertexs.GetSize()-1] = pt;
		}
		else
		{
			// direction changed, has to add a new vertex
			vertexs.Add(pt);
		}
		if(vertexs.GetSize()%3000==0)
			TRACE(_T("Add point: %d,%d, number %d\n"),pt.x,pt.y,vertexs.GetSize());
	} while (pt != pt1);

	m_rgn.DeleteObject();
	if (!m_rgn.CreatePolygonRgn(vertexs.GetData(), PtrToInt(vertexs.GetSize()), ALTERNATE))
	{
		ASSERT((HRGN)m_rgn == NULL);
		return FALSE;
	}

	return TRUE;
}