Skip to content
This repository has been archived by the owner on Feb 28, 2021. It is now read-only.

Commit

Permalink
Adding polylines.
Browse files Browse the repository at this point in the history
  • Loading branch information
ttvd committed Apr 30, 2017
1 parent a62d438 commit fd28ff7
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 9 deletions.
74 changes: 65 additions & 9 deletions SOP_Shapefile.C
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#define SOP_SHAPEFILE_GROUP_SHAPE_POINT "shape_point"
#define SOP_SHAPEFILE_GROUP_SHAPE_POLYGON "shape_polygon"
#define SOP_SHAPEFILE_GROUP_SHAPE_POLYLINE "shape_polyline"


static PRM_Name s_name_file(SOP_SHAPEFILE_PARAM_FILE, "Shape File");
Expand Down Expand Up @@ -157,7 +158,13 @@ SOP_Shapefile::cookMySop(OP_Context& context)
}

case SHPT_ARC:
case SHPT_ARCZ:
{
if(!addShapePolyline(shp_object, t))
{
processWarning("Skipping an invalid polyline shape.");
}

break;
}

Expand All @@ -173,17 +180,9 @@ SOP_Shapefile::cookMySop(OP_Context& context)
}

case SHPT_MULTIPOINT:
{
break;
}

case SHPT_ARCZ:
{
break;
}

case SHPT_MULTIPOINTZ:
{
processWarning("Skipping unsupported mulitpoint shape.");
break;
}

Expand Down Expand Up @@ -442,6 +441,63 @@ SOP_Shapefile::addShapePolygon(SHPObject* shp_object, fpreal t)
}


bool
SOP_Shapefile::addShapePolyline(SHPObject* shp_object, fpreal t)
{
if(!shp_object)
{
return false;
}

if(shp_object->nSHPType != SHPT_ARC && shp_object->nSHPType != SHPT_ARCZ)
{
return false;
}

GA_PrimitiveGroup* group_primitive = nullptr;
if(getParamCreateShapeGroups(t))
{
group_primitive = findGroupPrimitive(SOP_SHAPEFILE_GROUP_SHAPE_POLYLINE);
}

for(int idp = 0; idp < shp_object->nParts; ++idp)
{
UT_Array<UT_Vector3> point_positions;
if(!getShapePointPositions(shp_object, idp, (shp_object->nSHPType == SHPT_ARCZ), point_positions))
{
return false;
}

GU_PrimPoly* prim_poly = GU_PrimPoly::build(gdp, 0, GU_POLY_OPEN);

for(int idx = 0; idx < point_positions.size(); ++idx)
{
const UT_Vector3& point_position = point_positions(idx);

GA_Offset point_offset = gdp->appendPoint();
gdp->setPos3(point_offset, point_position);

prim_poly->appendVertex(point_offset);
}

if(group_primitive)
{
GA_Offset prim_offset = prim_poly->getMapOffset();
group_primitive->addOffset(prim_offset);
}

if(getParamCreateShapeAttributes(t))
{
GA_Offset prim_offset = prim_poly->getMapOffset();
setPrimitiveAttributeShapeNumber(prim_offset, shp_object->nShapeId);
setPrimitiveAttributeShapePartNumber(prim_offset, idp);
}
}

return true;
}


GA_PointGroup*
SOP_Shapefile::findGroupPoint(const UT_String& group_name) const
{
Expand Down
3 changes: 3 additions & 0 deletions SOP_Shapefile.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class SOP_Shapefile : public SOP_Node
//! Process polygon shapes.
bool addShapePolygon(SHPObject* shp_object, fpreal t);

//! Process polyline shape.
bool addShapePolyline(SHPObject* shp_object, fpreal t);

protected:

//! Helper function used to retrieve first and last vertex for a given shape part.
Expand Down

0 comments on commit fd28ff7

Please sign in to comment.