예제 #1
0
파일: hsh.cpp 프로젝트: rti-capture/rti-chi
int Hsh::loadCompressed()
{
	if (filename.isEmpty())
		return -1;
	else
		return loadCompressed(filename);
}
예제 #2
0
	SerializedMesh(const Properties &props) : TriMesh(props) {
		fs::path filePath = Thread::getThread()->getFileResolver()->resolve(
			props.getString("filename"));

		/* Object-space -> World-space transformation */
		Transform objectToWorld = props.getTransform("toWorld", Transform());

		/// When the file contains multiple meshes, this index specifies which one to load
		int shapeIndex = props.getInteger("shapeIndex", 0);

		m_name = (props.getID() != "unnamed") ? props.getID()
			: formatString("%s@%i", filePath.stem().string().c_str(), shapeIndex);

		/* Load the geometry */
		Log(EInfo, "Loading shape %i from \"%s\" ..", shapeIndex, filePath.filename().string().c_str());
		ref<FileStream> stream = new FileStream(filePath, FileStream::EReadOnly);
		ref<Timer> timer = new Timer();
		loadCompressed(stream, shapeIndex);
		Log(EDebug, "Done (" SIZE_T_FMT " triangles, " SIZE_T_FMT " vertices, %i ms)",
			m_triangleCount, m_vertexCount, timer->getMilliseconds());

		/* By default, any existing normals will be used for
		   rendering. If no normals are found, Mitsuba will
		   automatically generate smooth vertex normals.
		   Setting the 'faceNormals' parameter instead forces
		   the use of face normals, which will result in a faceted
		   appearance.
		*/
		m_faceNormals = props.getBoolean("faceNormals", false);

		/* Causes all normals to be flipped */
		m_flipNormals = props.getBoolean("flipNormals", false);

		if (!objectToWorld.isIdentity()) {
			m_aabb.reset();
			for (size_t i=0; i<m_vertexCount; ++i) {
				Point p = objectToWorld(m_positions[i]);
				m_positions[i] = p;
				m_aabb.expandBy(p);
			}
			if (m_normals) {
				for (size_t i=0; i<m_vertexCount; ++i)
					m_normals[i] = objectToWorld(m_normals[i]);
			}
		}

		if (objectToWorld.det3x3() < 0) {
			for (size_t i=0; i<m_triangleCount; ++i) {
				Triangle &t = m_triangles[i];
				std::swap(t.idx[0], t.idx[1]);
			}
		}

		if (props.hasProperty("maxSmoothAngle")) {
			if (m_faceNormals)
				Log(EError, "The properties 'maxSmoothAngle' and 'faceNormals' "
				"can't be specified at the same time!");
			rebuildTopology(props.getFloat("maxSmoothAngle"));
		}
	}
예제 #3
0
bool PictureShared::load(QIODevice* io, const QString& extension)
{
    kDebug(30508) << "PictureShared::load(QIODevice*, const QString&)" << extension;
    bool flag = false;
    QString ext(extension.toLower());
    if (ext == "tmp") // ### TODO: also remote scripts need this, don't they?
        flag = loadTmp(io);
    else if (ext == "bz2") {
        flag = loadCompressed(io, "application/x-bzip", "tmp");
    } else if (ext == "gz") {
        flag = loadCompressed(io, "application/x-gzip", "tmp");
    } else if (ext == "svgz") {
        flag = loadCompressed(io, "application/x-gzip", "svg");
    } else {
        clearAndSetMode(ext);
        if (m_base)
            flag = m_base->load(io, ext);
        setExtension(ext);
    }
    if (!flag) {
        kError(30508) << "File was not loaded! (PictureShared::load)" << endl;
    }
    return flag;
}
예제 #4
0
bool PictureShared::identifyAndLoad(const QByteArray& _array)
{
    if (_array.size() < 5) {
        kError(30508) << "Picture is less than 5 bytes long!" << endl;
        return false;
    }

    QByteArray array = _array;

    QString strExtension;
    bool flag = false;

    // Try to find the file type by comparing magic on the first few bytes!
    // ### TODO: could not QImageIO::imageFormat do it too? (At least most of them?)
    if ((array[0] == char(0x89)) && (array[1] == 'P') && (array[2] == 'N') && (array[3] == 'G')) {
        strExtension = "png";
    } else if ((array[0] == char(0xff)) && (array[1] == char(0xd8)) && (array[2] == char(0xff)) && (array[3] == char(0xe0))) {
        strExtension = "jpeg";
    } else if ((array[0] == 'B') && (array[1] == 'M')) {
        strExtension = "bmp";
    } else if ((array[0] == '<') && (array[1] == '?') && (array[2] == 'x') && (array[3] == 'm') && (array[4] == 'l')) {
        strExtension = "svg";
    } else if ((array[0] == 'Q') && (array[1] == 'P') && (array[2] == 'I') && (array[3] == 'C')) {
        strExtension = "qpic";
    } else if ((array[0] == '%') && (array[1] == '!') && (array[2] == 'P') && (array[3] == 'S')) {
        strExtension = "eps";
    } else if ((array[0] == char(0xc5)) && (array[1] == char(0xd0)) && (array[2] == char(0xd3)) && (array[3] == char(0xc6))) {
        // So called "MS-DOS EPS file"
        strExtension = "eps";
    } else if ((array[0] == 'G') && (array[1] == 'I') && (array[2] == 'F') && (array[3] == '8')) {
        // GIF (87a or 89a)
        strExtension = "gif";
    } else if ((array[0] == char(0037)) && (array[1] == char(0213))) {
        // Gzip
        QBuffer buffer(&array);
        buffer.open(QIODevice::ReadOnly);

        const bool flag = loadCompressed(&buffer, "application/x-gzip", "tmp");
        buffer.close();
        return flag;
    } else if ((array[0] == 'B') && (array[1] == 'Z') && (array[2] == 'h')) {
        // BZip2
        QBuffer buffer(&array);
        buffer.open(QIODevice::ReadOnly);
        const bool flag = loadCompressed(&buffer, "application/x-bzip", "tmp");
        buffer.close();
        return flag;
    } else {
        kDebug(30508) << "Cannot identify the type of temp file!"
        << " Trying to convert to PNG! (in PictureShared::loadTmp" << endl;

        // Do not trust QBuffer and do not work directly on the QByteArray array
        // DF: It would be faster to work on array here, and to create a completely
        // different QBuffer for the writing code!
        QBuffer buf(&array);
        if (!buf.open(QIODevice::ReadOnly)) {
            kError(30508) << "Could not open read buffer!" << endl;
            return false;
        }

        QImageReader imageReader(&buf);
        QImage image = imageReader.read();
        if (image.isNull()) {
            kError(30508) << "Could not read image!" << endl;
            return false;
        }
        buf.close();

        if (!buf.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
            kError(30508) << "Could not open write buffer!" << endl;
            return false;
        }

        QImageWriter imageWriter(&buf, "PNG");

        if (!imageWriter.write(image)) {
            kError(30508) << "Could not write converted image!" << endl;
            return false;
        }
        buf.close();

        array = buf.buffer();

        strExtension = "png";
    }

    kDebug(30508) << "Temp file considered to be" << strExtension;

    clearAndSetMode(strExtension);
    if (m_base)
        flag = m_base->loadData(array, strExtension);
    setExtension(strExtension);

    return flag;
}
예제 #5
0
파일: hsh.cpp 프로젝트: rti-capture/rti-chi
int Hsh::loadCompressed(QString name)
{
	return loadCompressed(0,0,w,h,name);
}
예제 #6
0
파일: ptm.cpp 프로젝트: rti-capture/rti-chi
int LRGBPtm::loadCompressed(QString name)
{
	return loadCompressed(0,0,w,h,name);
}
예제 #7
0
파일: ptm.cpp 프로젝트: rti-capture/rti-chi
int RGBPtm::loadCompressed(QString name)
{
	remote = false;
	return loadCompressed(0,0,w,h,name);
}