Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ply reading in windows #2071

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 57 additions & 1 deletion projects/CalcGeometryUV/PrimitivePlyIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define TINYPLY_IMPLEMENTATION
#include "primplyio_tinyply.h"

#include "happly.h"

/*
static void readply(
Expand Down Expand Up @@ -123,18 +124,72 @@ static void readply(
}
}
*/

static void ReadAllAttrFromPlyFile(std::string &ply_file, std::shared_ptr<zeno::PrimitiveObject> prim){
std::filesystem::path file_path(ply_file);
if(!std::filesystem::exists(file_path)){
throw std::runtime_error(ply_file + " not exsit");
return;
}

std::ifstream file_stream;
file_stream.open(file_path);
file_stream.open(file_path,std::ios::binary);
if(!file_stream.is_open()){
throw std::runtime_error("fail to open "+ply_file);
return;
}

happly::PLYData ply_obj(file_stream);
try{
ply_obj.validate();
}catch(std::exception &e){
std::cerr << e.what() << std::endl;
throw e;
return;
}
std::vector<std::string> element_names = ply_obj.getElementNames();
for(std::string element_name : element_names){
std::cout << element_name << "\n |\n";
std::vector<std::string>property_names = ply_obj.getElement(element_name).getPropertyNames();
for(std::string property_name : property_names){
std::cout << "\t|--" << property_name << std::endl;
}

}
happly::Element& vertex = ply_obj.getElement("vertex");
std::cout << "Vertex count = " <<vertex.count << std::endl;
prim->verts.resize(vertex.count);
std::vector<std::string> property_names = vertex.getPropertyNames();
for(std::string property_name : property_names){
std::vector<float> &new_property = prim->add_attr<float>(property_name);
try{
std::vector<float> data = vertex.getProperty<float>(property_name);
new_property.assign(data.begin(),data.end());
}catch(std::exception &e){
std::cerr << e.what() << std::endl;
throw e;
return;
}
}
return;

}

/*
static void ReadAllAttrFromPlyFile(std::string &ply_file, std::shared_ptr<zeno::PrimitiveObject> prim){
std::filesystem::path file_path(ply_file);
if(!std::filesystem::exists(file_path)){
throw std::runtime_error(ply_file + " not exsit");
return;
}

std::ifstream file_stream;
file_stream.open(file_path,std::ios::binary);
if(!file_stream.is_open()){
throw std::runtime_error("fail to open "+ply_file);
return;
}

tinyply::PlyFile ply_obj;
if(!ply_obj.parse_header(file_stream)){
throw std::runtime_error("fail to parse ply header");
Expand Down Expand Up @@ -210,6 +265,7 @@ static void ReadAllAttrFromPlyFile(std::string &ply_file, std::shared_ptr<zeno::
}

}
*/

struct ReadPlyPrimitive : zeno::INode {
virtual void apply() override {
Expand Down
Loading
Loading