EnvMap(const PropertyList &props) : Emitter(props.getTransform("toWorld", Transform())) { //set the arguments std::string filePath = props.getString("lightProbPath", ""); filesystem::path path = getFileResolver()->resolve(filePath); //try to set it try { if (path.extension() == "exr") { m_lightprobe = new Bitmap(path.str()); m_wrapper = new HSWrapper(*m_lightprobe); m_latlngMap = new LatLongMap(); m_BBox.min = Point2i(0, 0); m_BBox.max = Point2i(m_lightprobe->cols(), m_lightprobe->rows()); m_width = m_lightprobe->cols(); m_height = m_lightprobe->rows(); } else { cerr << "Fatal error: unknown file \"" << filePath << "\", expected an extension of type .exr" << endl; } } catch (const std::exception &e) { cerr << "Fatal error: " << e.what() << endl; } }
WavefrontOBJ(const PropertyList &propList) { typedef boost::unordered_map<OBJVertex, uint32_t, OBJVertexHash> VertexMap; /* Process the OBJ-file line by line */ QString filename = propList.getString("filename"); QFile input(filename); if (!input.open(QIODevice::ReadOnly | QIODevice::Text)) throw NoriException(QString("Cannot open \"%1\"").arg(filename)); Transform trafo = propList.getTransform("toWorld", Transform()); cout << "Loading \"" << qPrintable(filename) << "\" .." << endl; m_name = filename; QTextStream stream(&input); QTextStream line; QString temp, prefix; std::vector<Point3f> positions; std::vector<Point2f> texcoords; std::vector<Normal3f> normals; std::vector<uint32_t> indices; std::vector<OBJVertex> vertices; VertexMap vertexMap; while (!(temp = stream.readLine()).isNull()) { line.setString(&temp); line >> prefix; if (prefix == "v") { Point3f p; line >> p.x() >> p.y() >> p.z(); p = trafo * p; positions.push_back(p); } else if (prefix == "vt") {
HeterogeneousMedium(const PropertyList &propList) { // Denotes the scattering albedo m_albedo = propList.getColor("albedo"); // An (optional) transformation that converts between medium and world coordinates m_worldToMedium = propList.getTransform("toWorld", Transform()).inverse(); // Optional multiplicative factor that will be applied to all density values in the file m_densityMultiplier = propList.getFloat("densityMultiplier", 1.0f); m_filename = propList.getString("filename"); QByteArray filename = m_filename.toLocal8Bit(); QFile file(m_filename); if (!file.exists()) throw NoriException(QString("The file \"%1\" does not exist!").arg(m_filename)); /* Parse the file header */ file.open(QIODevice::ReadOnly); QDataStream stream(&file); stream.setByteOrder(QDataStream::LittleEndian); qint8 header[3], version; qint32 type; stream >> header[0] >> header[1] >> header[2] >> version >> type; if (memcmp(header, "VOL", 3) != 0 || version != 3) throw NoriException("This is not a valid volume data file!"); stream >> m_resolution.x() >> m_resolution.y() >> m_resolution.z(); file.close(); cout << "Mapping \"" << filename.data() << "\" (" << m_resolution.x() << "x" << m_resolution.y() << "x" << m_resolution.z() << ") into memory .." << endl; m_fileSize = (size_t) file.size(); #if defined(PLATFORM_LINUX) || defined(PLATFORM_MACOS) int fd = open(filename.data(), O_RDONLY); if (fd == -1) throw NoriException(QString("Could not open \"%1\"!").arg(m_filename)); m_data = (float *) mmap(NULL, m_fileSize, PROT_READ, MAP_SHARED, fd, 0); if (m_data == NULL) throw NoriException("mmap(): failed."); if (close(fd) != 0) throw NoriException("close(): unable to close file descriptor!"); #elif defined(PLATFORM_WINDOWS) m_file = CreateFileA(filename.data(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (m_file == INVALID_HANDLE_VALUE) throw NoriException(QString("Could not open \"%1\"!").arg(m_filename)); m_fileMapping = CreateFileMapping(m_file, NULL, PAGE_READONLY, 0, 0, NULL); if (m_fileMapping == NULL) throw NoriException("CreateFileMapping(): failed."); m_data = (float *) MapViewOfFile(m_fileMapping, FILE_MAP_READ, 0, 0, 0); if (m_data == NULL) throw NoriException("MapViewOfFile(): failed."); #endif m_data += 12; // Shift past the header }