Example #1
0
	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") {
Example #2
0
    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;
        }
    }
Example #3
0
	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
	}
Example #4
0
    StudentsTTest(const PropertyList &propList) {
        /* The null hypothesis will be rejected when the associated
           p-value is below the significance level specified here. */
        m_significanceLevel = propList.getFloat("significanceLevel", 0.01f);

        /* This parameter specifies a list of incidence angles that will be tested */
        std::vector<std::string> angles = tokenize(propList.getString("angles", ""));
        for (auto angle : angles)
            m_angles.push_back(toFloat(angle));

        /* This parameter specifies a list of reference values, one for each angle */
        std::vector<std::string> references = tokenize(propList.getString("references", ""));
        for (auto angle : references)
            m_references.push_back(toFloat(angle));

        /* Number of BSDF samples that should be generated (default: 100K) */
        m_sampleCount = propList.getInteger("sampleCount", 100000);
    }
Example #5
0
	Path(const PropertyList &propList) {
		m_maxDepth = propList.getInteger("maxDepth", 13);
		QString samplePolicy = propList.getString("samplePolicy", "SampleBoth");
		if (samplePolicy == "SampleBsdf") {
			m_samplePolicy = ESampleBsdf;
		} else if (samplePolicy == "sampleLight") {
			m_samplePolicy = ESampleLight;
		} else {
			m_samplePolicy = EMis;
		}
	}
Example #6
0
    Conductor(const PropertyList &propList) {
        materialName = propList.getString("materialName", "");

        if(materialName != "") {
            // load the specific material properties
            if(!getMaterialProperties(materialName, m_eta, m_k)){
                std::cout << "Material " << materialName << " not found!" << std::endl;
            }
        } else {
            m_eta = propList.getColor("eta");
            m_k = propList.getColor("k");
        }
    }
Example #7
0
    RoughConductor(const PropertyList &propList) {
        materialName = propList.getString("materialName", "");

        if(materialName != "") {
            // load the specific material properties
            if(!getMaterialProperties(materialName, m_eta, m_k)){
                std::cout << "Material " << materialName << " not found!" << std::endl;
            }
        } else {
            m_eta = propList.getColor("eta");
            m_k = propList.getColor("k");
        }

        /* RMS surface roughness */
        m_alpha = propList.getFloat("alpha", 0.1f);
    }
Example #8
0
std::shared_ptr<Object> ObjectFactory :: create(std::string name, std::string type)
{
    // create an Object class as a prototype to open config file of above name
    std::unique_ptr<Object> prototype;

    if(!Filesystem::hasExtension(name))
        name += ".ini";
    
    // deduce type from ini
    if(type.empty())
    {
        // trying to deduce type of object without extension is impossible
        if(!Filesystem::hasExtension(name, "ini"))
        {
            assert(false);
            return std::shared_ptr<Object>();
        }

        PropertyList properties;
        boost::filesystem::path path = System::get().imageResources().locate(name);
        name = path.string();

        if(!properties.open(name.c_str()))
        {
            assert(false);
            return std::shared_ptr<Object>();
        }
        type = properties.getString("default", "type", "");
        if(type.empty())
        {
            assert(false);
            return std::shared_ptr<Object>();
        }
    }   

    //// locate an object
    //if(Filesystem::hasExtension("ini"))
    //{
    //    std::vector<boost::filesystem::path> search_paths;
    //    if(type == "backdrop")
    //        search_paths.push_back(boost::filesystem::path("data/backdrops/"));
    //    else
    //        search_paths.push_back(boost::filesystem::path("data/objects/"));
    //    std::vector<std::string> extensions;

    //    extensions.push_back("ini"); // load as image

    //    boost::filesystem::path found = Filesystem::locate(name, search_paths, extensions);
    //    if(found)
    //        name = found.string();
    //}

    // dispatch pattern by object type, return Object pointer
    try{
        std::shared_ptr<Object> object;
        // add more object types to this list
        if(type == "enemy")
            object.reset(new Enemy(name));
        else if(type == "particle")
            object.reset(new Particle(name));
        else if(type == "backdrop")
            object.reset(new Backdrop(name));
        else if(type == "item")
            object.reset(new Item(name));
        else
            return std::shared_ptr<Object>();

        if(object)
            m_pWorld->add(object);
        return object;
    } catch(const Failure& f){
        assert(false);
    }

    return std::shared_ptr<Object>();
}