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

Commit

Permalink
Some final fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ttvd committed Apr 30, 2017
1 parent fd28ff7 commit 198768d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
32 changes: 26 additions & 6 deletions SOP_Shapefile.C
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define SOP_SHAPEFILE_PARAM_FILE "shape_file"
#define SOP_SHAPEFILE_PARAM_CREATE_SHAPE_GROUPS "create_shape_groups"
#define SOP_SHAPEFILE_PARAM_CREATE_SHAPE_ATTRIBUTES "create_shape_attributes"
#define SOP_SHAPEFILE_PARAM_SWAP_YZ_AXIS "swap_yz_axis"

#define SOP_SHAPEFILE_ATTRIB_POINT_SHAPE_NUM "point_shape_num"
#define SOP_SHAPEFILE_ATTRIB_POINT_SHAPE_PART_NUM "point_shape_part_num"
Expand All @@ -35,20 +36,23 @@
static PRM_Name s_name_file(SOP_SHAPEFILE_PARAM_FILE, "Shape File");
static PRM_Name s_name_create_shape_groups(SOP_SHAPEFILE_PARAM_CREATE_SHAPE_GROUPS, "Create Shape Groups");
static PRM_Name s_name_create_shape_attributes(SOP_SHAPEFILE_PARAM_CREATE_SHAPE_ATTRIBUTES, "Create Shape Attributes");
static PRM_Name s_name_swap_yz_axis(SOP_SHAPEFILE_PARAM_SWAP_YZ_AXIS, "Swap YZ Axis");
static PRM_SpareData s_shape_file_picker(PRM_SpareArgs() << PRM_SpareToken(PRM_SpareData::getFileChooserModeToken(),
PRM_SpareData::getFileChooserModeValRead()) << PRM_SpareToken(PRM_SpareData::getFileChooserPatternToken(),
SOP_Shapefile::fileExtensionFilterString()));


static PRM_Default s_default_create_shape_groups(false);
static PRM_Default s_default_create_shape_attributes(false);
static PRM_Default s_default_swap_yz_axis(true);


PRM_Template
SOP_Shapefile::myTemplateList[] =
{
PRM_Template(PRM_TOGGLE, 1, &s_name_create_shape_groups, &s_default_create_shape_groups),
PRM_Template(PRM_TOGGLE, 1, &s_name_create_shape_attributes, &s_default_create_shape_attributes),
PRM_Template(PRM_TOGGLE, 1, &s_name_swap_yz_axis, &s_default_swap_yz_axis),
PRM_Template(PRM_FILE, 1, &s_name_file, 0, 0, 0, 0, &s_shape_file_picker),
PRM_Template()
};
Expand Down Expand Up @@ -266,13 +270,20 @@ SOP_Shapefile::getParamCreateShapeAttributes(fpreal t) const
}


bool
SOP_Shapefile::getParamSwapYZAxis(fpreal t) const
{
return evalInt(SOP_SHAPEFILE_PARAM_SWAP_YZ_AXIS, 0, t) != 0;
}


bool
SOP_Shapefile::getShapeVertexIndices(SHPObject* shp_object, int part_idx, int& vertex_first, int& vertex_last) const
{
vertex_first = 0;
vertex_last = 0;

if(!shp_object || part_idx < 0 || shp_object->nParts >= part_idx)
if(!shp_object || part_idx < 0 || shp_object->nParts <= part_idx)
{
return false;
}
Expand All @@ -294,7 +305,7 @@ SOP_Shapefile::getShapeVertexIndices(SHPObject* shp_object, int part_idx, int& v


bool
SOP_Shapefile::getShapePointPositions(SHPObject* shp_object, int shp_idx, bool use_z,
SOP_Shapefile::getShapePointPositions(SHPObject* shp_object, int shp_idx, bool use_z, fpreal t,
UT_Array<UT_Vector3>& point_positions) const
{
point_positions.clear();
Expand All @@ -307,6 +318,8 @@ SOP_Shapefile::getShapePointPositions(SHPObject* shp_object, int shp_idx, bool u
int vertex_first = 0;
int vertex_last = 0;

bool swap_yz_axis = getParamSwapYZAxis(t);

if(!getShapeVertexIndices(shp_object, shp_idx, vertex_first, vertex_last))
{
return false;
Expand All @@ -324,7 +337,14 @@ SOP_Shapefile::getShapePointPositions(SHPObject* shp_object, int shp_idx, bool u
pz = shp_object->padfZ[idx];
}

point_positions.append(UT_Vector3(px, py, pz));
if(swap_yz_axis)
{
point_positions.append(UT_Vector3(px, pz, py));
}
else
{
point_positions.append(UT_Vector3(px, py, pz));
}
}

return point_positions.size() > 0;
Expand Down Expand Up @@ -353,7 +373,7 @@ SOP_Shapefile::addShapePoint(SHPObject* shp_object, fpreal t)
for(int idp = 0; idp < shp_object->nParts; ++idp)
{
UT_Array<UT_Vector3> point_positions;
if(!getShapePointPositions(shp_object, idp, (shp_object->nSHPType == SHPT_POINTZ), point_positions))
if(!getShapePointPositions(shp_object, idp, (shp_object->nSHPType == SHPT_POINTZ), t, point_positions))
{
return false;
}
Expand Down Expand Up @@ -404,7 +424,7 @@ SOP_Shapefile::addShapePolygon(SHPObject* shp_object, fpreal t)
for(int idp = 0; idp < shp_object->nParts; ++idp)
{
UT_Array<UT_Vector3> point_positions;
if(!getShapePointPositions(shp_object, idp, (shp_object->nSHPType == SHPT_POLYGONZ), point_positions))
if(!getShapePointPositions(shp_object, idp, (shp_object->nSHPType == SHPT_POLYGONZ), t, point_positions))
{
return false;
}
Expand Down Expand Up @@ -463,7 +483,7 @@ SOP_Shapefile::addShapePolyline(SHPObject* shp_object, fpreal t)
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))
if(!getShapePointPositions(shp_object, idp, (shp_object->nSHPType == SHPT_ARCZ), t, point_positions))
{
return false;
}
Expand Down
6 changes: 5 additions & 1 deletion SOP_Shapefile.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class SOP_Shapefile : public SOP_Node
bool getShapeVertexIndices(SHPObject* shp_object, int part_idx, int& vertex_first, int& vertex_last) const;

//! Given a shape and shape index, retrieve points.
bool getShapePointPositions(SHPObject* shp_object, int shape_idx, bool use_z, UT_Array<UT_Vector3>& point_positions) const;
bool getShapePointPositions(SHPObject* shp_object, int shape_idx, bool use_z, fpreal t,
UT_Array<UT_Vector3>& point_positions) const;

protected:

Expand Down Expand Up @@ -87,6 +88,9 @@ class SOP_Shapefile : public SOP_Node
//! Retrieve whether to create shape attributes.
bool getParamCreateShapeAttributes(fpreal t) const;

//! Retrieve whether to flip YZ axis.
bool getParamSwapYZAxis(fpreal t) const;

protected:

virtual OP_ERROR cookMySop(OP_Context& context);
Expand Down

0 comments on commit 198768d

Please sign in to comment.