static void parse_elements (const std::string &name, TypeDesc type, const std::string &type_code, const std::string &elements, int num_elements, ImageIOParameter ¶m) { void *data = new T[num_elements]; char *data_ptr = (char *) data; size_t element_size = type.elementtype().elementsize (); boost::char_separator<char> sep (", "); boost::tokenizer<boost::char_separator<char> > tokens (elements, sep); BOOST_FOREACH (std::string element, tokens) { sscanf (element.c_str (), type_code.c_str (), (T *)data_ptr); data_ptr += element_size; }
void OSLCompilerImpl::write_oso_const_value (const ConstantSymbol *sym) const { ASSERT (sym); TypeDesc type = sym->typespec().simpletype(); TypeDesc elemtype = type.elementtype(); int nelements = std::max (1, type.arraylen); if (elemtype == TypeDesc::STRING) for (int i = 0; i < nelements; ++i) oso ("\"%s\"%s", sym->strval(i).c_str(), nelements>1 ? " " : ""); else if (elemtype == TypeDesc::INT) for (int i = 0; i < nelements; ++i) oso ("%d%s", sym->intval(i), nelements>1 ? " " : ""); else if (elemtype == TypeDesc::FLOAT) for (int i = 0; i < nelements; ++i) oso ("%.8g%s", sym->floatval(i), nelements>1 ? " " : ""); else if (equivalent (elemtype, TypeDesc::TypeVector)) for (int i = 0; i < nelements; ++i) oso ("%.8g %.8g %.8g%s", sym->vecval(i)[0], sym->vecval(i)[1], sym->vecval(i)[2], nelements>1 ? " " : ""); else { ASSERT (0 && "Don't know how to output this constant type"); } }
int RendererServices::pointcloud_get (ShaderGlobals *sg, ustring filename, size_t *indices, int count, ustring attr_name, TypeDesc attr_type, void *out_data) { #if USE_PARTIO if (! count) return 1; // always succeed if not asking for any data PointCloud *pc = PointCloud::get(filename); if (pc == NULL) { // The file failed to load sg->context->shadingsys().error ("pointcloud_get: could not open \"%s\"", filename.c_str()); return 0; } spin_lock lock (pc->m_mutex); Partio::ParticlesDataMutable *cloud = pc->m_partio_cloud; if (cloud == NULL) { // The file failed to load sg->context->shadingsys().error ("pointcloud_get: could not open \"%s\"", filename.c_str()); return 0; } // lookup the ParticleAttribute pointer needed for a query Partio::ParticleAttribute *attr = pc->m_attributes[attr_name].get(); if (! attr) { sg->context->shadingsys().error ("Accessing unexisting attribute %s in pointcloud \"%s\"", attr_name.c_str(), filename.c_str()); return 0; } // Now make sure that types are compatible TypeDesc element_type = attr_type.elementtype (); int attr_partio_type = 0; // Convert the OSL (OIIO) type to the equivalent Partio type if (element_type == TypeDesc::TypeFloat) attr_partio_type = Partio::FLOAT; else if (element_type == TypeDesc::TypeInt) attr_partio_type = Partio::INT; else if (element_type == TypeDesc::TypeColor || element_type == TypeDesc::TypePoint || element_type == TypeDesc::TypeVector || element_type == TypeDesc::TypeNormal) attr_partio_type = Partio::VECTOR; else { // error ("Unsupported attribute type %s for pointcloud query in attribute %s", // element_type.c_str(), attr_name.c_str()); return 0; } // Finally check for some equivalent types like float3 and vector if (!compatiblePartioType(attr, attr_partio_type)) { sg->context->shadingsys().error ("Type of attribute \"%s\" : %s[%d] not compatible with OSL's %s in \"%s\" pointcloud", attr_name.c_str(), partioTypeString(attr), attr->count, element_type.c_str(), filename.c_str()); return 0; } ASSERT (sizeof(size_t) == sizeof(Partio::ParticleIndex) && "Only will work if Partio ParticleIndex is the size of a size_t"); // FIXME -- if anybody cares about an architecture in which that is not // the case, we can easily allocate local space to retrieve the indices, // then copy them back to the caller's indices. // Actual data query cloud->data (*attr, count, (Partio::ParticleIndex *)indices, true, out_data); return 1; #else return 0; #endif }
static bool grep_file (const std::string &filename, boost::regex &re, bool ignore_nonimage_files=false) { if (! Filesystem::exists (filename)) { std::cerr << "igrep: " << filename << ": No such file or directory\n"; return false; } if (Filesystem::is_directory (filename)) { if (! recursive) return false; if (print_dirs) { std::cout << "(" << filename << "/)\n"; std::cout.flush(); } bool r = false; std::vector<std::string> directory_entries; Filesystem::get_directory_entries (filename, directory_entries); for (size_t i = 0, e = directory_entries.size(); i < e; ++i) r |= grep_file (directory_entries[i], re, true); return r; } std::unique_ptr<ImageInput> in (ImageInput::open (filename.c_str())); if (! in.get()) { if (! ignore_nonimage_files) std::cerr << geterror() << "\n"; return false; } ImageSpec spec = in->spec(); if (file_match) { bool match = boost::regex_search (filename, re); if (match && ! invert_match) { std::cout << filename << "\n"; return true; } } bool found = false; int subimage = 0; do { if (!all_subimages && subimage > 0) break; for (auto&& p : spec.extra_attribs) { TypeDesc t = p.type(); if (t.elementtype() == TypeDesc::STRING) { int n = t.numelements(); for (int i = 0; i < n; ++i) { bool match = boost::regex_search (((const char **)p.data())[i], re); found |= match; if (match && ! invert_match) { if (list_files) { std::cout << filename << "\n"; return found; } std::cout << filename << ": " << p.name() << " = " << ((const char **)p.data())[i] << "\n"; } } } } } while (in->seek_subimage (++subimage, 0, spec)); if (invert_match) { found = !found; if (found) std::cout << filename << "\n"; } return found; }