//---------------------------------------------------------
void CGrid_3D_Image::_Set_Shapes(CSG_Shapes *pInput)
{
	int			iShape, iPart, iPoint;
	double		x, y, z, dx, dy;
	T3DPoint	p;
	TSG_Point	Point;
	CSG_Shape		*pShape;
	CSG_Shapes		*pOutput;

	if( pInput && pInput->is_Valid() )
	{
		Process_Set_Text("%s \"%s\"", _TL("Project"), pInput->Get_Name());

		pOutput	= SG_Create_Shapes(*pInput);
		dx		= (double)Get_NX() / Get_System().Get_XRange();
		dy		= (double)Get_NY() / Get_System().Get_YRange();

		for(iShape=0; iShape<pOutput->Get_Count() && Set_Progress(iShape, pOutput->Get_Count()); iShape++)
		{
			pShape	= pOutput->Get_Shape(iShape);

			for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
			{
				for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
				{
					Point	= pShape->Get_Point(iPoint, iPart);

					x		= dx * (Point.x - Get_XMin());
					y		= dy * (Point.y - Get_YMin());
					z		= m_pDEM->is_InGrid((int)x, (int)y, true) ? m_pDEM->asDouble((int)x, (int)y) : 0.0;

					_Get_Position(x, y, z, p);

					pShape->Set_Point(p.x, p.y, iPoint, iPart);
				}
			}
		}

		DataObject_Add(pOutput);
	}
}
//---------------------------------------------------------
CSG_Shape * CSG_PointCloud::_Set_Shape(int iPoint)
{
    SG_UI_Progress_Lock(true);

    CSG_Shape	*pShape	= m_Shapes.Get_Shape(0);

    if( pShape->is_Modified() && m_Shapes_Index >= 0 && m_Shapes_Index < Get_Count() )
    {
        m_Cursor	= m_Points[m_Shapes_Index];

        for(int i=0; i<Get_Field_Count(); i++)
        {
            switch( Get_Field_Type(i) )
            {
            default:
                Set_Value(i, pShape->asDouble(i));
                break;

            case SG_DATATYPE_Date:
            case SG_DATATYPE_String:
                Set_Value(i, pShape->asString(i));
                break;
            }
        }

        Set_Value(0, pShape->Get_Point(0).x);
        Set_Value(1, pShape->Get_Point(0).y);
        Set_Value(2, pShape->Get_Z    (0)  );
    }

    if( iPoint >= 0 && iPoint < Get_Count() )
    {
        if(1|| iPoint != m_Shapes_Index )
        {
            m_Cursor	= m_Points[iPoint];

            pShape->Set_Point(Get_X(), Get_Y(), 0, 0);
            pShape->Set_Z    (Get_Z()         , 0, 0);

            for(int i=0; i<Get_Field_Count(); i++)
            {
                switch( Get_Field_Type(i) )
                {
                default:
                    pShape->Set_Value(i, Get_Value(i));
                    break;

                case SG_DATATYPE_Date:
                case SG_DATATYPE_String:
                {
                    CSG_String	s;

                    Get_Value(i, s);

                    pShape->Set_Value(i, s);
                }
                break;
                }
            }

            m_Shapes_Index	= iPoint;
            pShape->m_Index	= iPoint;
            pShape->Set_Selected(is_Selected(iPoint));
        }

        m_Shapes.Set_Modified(false);

        SG_UI_Progress_Lock(false);

        return( pShape );
    }

    m_Shapes_Index	= -1;

    SG_UI_Progress_Lock(false);

    return( NULL );
}
示例#3
0
//---------------------------------------------------------
bool CWatershed_Segmentation::Get_Seeds(void)
{
    Process_Set_Text(_TL("Seeds"));

    bool	bEdge, bEdge_Seeds;
    int		x, y, i, ix, iy, iMax;
    double	z, dz, dzMax;

    //-----------------------------------------------------
    bEdge_Seeds	= Parameters("EDGE")	->asBool();

    //-----------------------------------------------------
    for(y=0; y<Get_NY() && Set_Progress(y); y++)
    {
        for(x=0; x<Get_NX(); x++)
        {
            if( !m_pGrid->is_InGrid(x, y) )
            {
                m_Dir.Set_Value(x, y, -1);
                m_pSegments->Set_NoData(x, y);
            }
            else
            {
                for(i=0, iMax=-1, dzMax=0.0, z=m_pGrid->asDouble(x, y), bEdge=false; i<8; i++)
                {
                    if( !m_pGrid->is_InGrid(ix = Get_xTo(i, x), iy = Get_yTo(i, y)) )
                    {
                        bEdge	= true;
                    }
                    else if( dzMax < (dz = (m_bDown ? m_pGrid->asDouble(ix, iy) - z : z - m_pGrid->asDouble(ix, iy)) / Get_Length(i)) )
                    {
                        dzMax	= dz;
                        iMax	= i;
                    }
                }

                //---------------------------------------------
                m_Dir.Set_Value(x, y, iMax);

                if( iMax < 0 && (bEdge_Seeds || !bEdge) )
                {
                    int			ID	= m_pSeeds->Get_Count();

                    CSG_Shape	*pSeed	= m_pSeeds->Add_Shape();

                    pSeed->Set_Point(Get_System()->Get_Grid_to_World(x, y), 0);

                    pSeed->Set_Value(SEED_X		, x);
                    pSeed->Set_Value(SEED_Y		, y);
                    pSeed->Set_Value(SEED_Z		, z);
                    pSeed->Set_Value(SEED_ID	, ID);
                    pSeed->Set_Value(SEED_JOIN	, -1);

                    m_pSegments->Set_Value(x, y, ID);
                }
                else
                {
                    m_pSegments->Set_Value(x, y, -1);
                }
            }
        }
    }

    return( m_pSeeds->Get_Count() > 1 );
}