FloatPoint TransformationMatrix::projectPoint(const FloatPoint& p) const { // This is basically raytracing. We have a point in the destination // plane with z=0, and we cast a ray parallel to the z-axis from that // point to find the z-position at which it intersects the z=0 plane // with the transform applied. Once we have that point we apply the // inverse transform to find the corresponding point in the source // space. // // Given a plane with normal Pn, and a ray starting at point R0 and // with direction defined by the vector Rd, we can find the // intersection point as a distance d from R0 in units of Rd by: // // d = -dot (Pn', R0) / dot (Pn', Rd) double x = p.x(); double y = p.y(); double z = -(m13() * x + m23() * y + m43()) / m33(); double outX = x * m11() + y * m21() + z * m31() + m41(); double outY = x * m12() + y * m22() + z * m32() + m42(); double w = x * m14() + y * m24() + z * m34() + m44(); if (w != 1 && w != 0) { outX /= w; outY /= w; } return FloatPoint(static_cast<float>(outX), static_cast<float>(outY)); }
//---------------------------------------- void ofNode::setGlobalOrientation(const ofQuaternion& q) { if(parent == NULL) { setOrientation(q); } else { ofMatrix4x4 invParent(ofMatrix4x4::getInverseOf(parent->getGlobalTransformMatrix())); ofMatrix4x4 m44(ofMatrix4x4(q) * invParent); setOrientation(m44.getRotate()); } }
const String DOMMatrixReadOnly::toString() const { std::stringstream stream; if (is2D()) { stream << "matrix(" << a() << ", " << b() << ", " << c() << ", " << d() << ", " << e() << ", " << f(); } else { stream << "matrix3d(" << m11() << ", " << m12() << ", " << m13() << ", " << m14() << ", " << m21() << ", " << m22() << ", " << m23() << ", " << m24() << ", " << m31() << ", " << m32() << ", " << m33() << ", " << m34() << ", " << m41() << ", " << m42() << ", " << m43() << ", " << m44(); } stream << ")"; return String(stream.str().c_str()); }
CSSFunctionValue* MatrixTransformComponent::toCSSValue() const { CSSFunctionValue* result = CSSFunctionValue::create(m_is2D ? CSSValueMatrix : CSSValueMatrix3d); if (m_is2D) { double values[6] = {a(), b(), c(), d(), e(), f()}; for (double value : values) { result->append(cssValuePool().createValue(value, CSSPrimitiveValue::UnitType::Number)); } } else { double values[16] = {m11(), m12(), m13(), m14(), m21(), m22(), m23(), m24(), m31(), m32(), m33(), m34(), m41(), m42(), m43(), m44() }; for (double value : values) { result->append(cssValuePool().createValue(value, CSSPrimitiveValue::UnitType::Number)); } } return result; }
TransformationMatrix::operator CATransform3D() const { CATransform3D toT3D; toT3D.m11 = narrowPrecisionToFloat(m11()); toT3D.m12 = narrowPrecisionToFloat(m12()); toT3D.m13 = narrowPrecisionToFloat(m13()); toT3D.m14 = narrowPrecisionToFloat(m14()); toT3D.m21 = narrowPrecisionToFloat(m21()); toT3D.m22 = narrowPrecisionToFloat(m22()); toT3D.m23 = narrowPrecisionToFloat(m23()); toT3D.m24 = narrowPrecisionToFloat(m24()); toT3D.m31 = narrowPrecisionToFloat(m31()); toT3D.m32 = narrowPrecisionToFloat(m32()); toT3D.m33 = narrowPrecisionToFloat(m33()); toT3D.m34 = narrowPrecisionToFloat(m34()); toT3D.m41 = narrowPrecisionToFloat(m41()); toT3D.m42 = narrowPrecisionToFloat(m42()); toT3D.m43 = narrowPrecisionToFloat(m43()); toT3D.m44 = narrowPrecisionToFloat(m44()); return toT3D; }
void OpenEXRInput::PartInfo::parse_header (const Imf::Header *header) { if (initialized) return; ASSERT (header); spec = ImageSpec(); top_datawindow = header->dataWindow(); top_displaywindow = header->displayWindow(); spec.x = top_datawindow.min.x; spec.y = top_datawindow.min.y; spec.z = 0; spec.width = top_datawindow.max.x - top_datawindow.min.x + 1; spec.height = top_datawindow.max.y - top_datawindow.min.y + 1; spec.depth = 1; topwidth = spec.width; // Save top-level mipmap dimensions topheight = spec.height; spec.full_x = top_displaywindow.min.x; spec.full_y = top_displaywindow.min.y; spec.full_z = 0; spec.full_width = top_displaywindow.max.x - top_displaywindow.min.x + 1; spec.full_height = top_displaywindow.max.y - top_displaywindow.min.y + 1; spec.full_depth = 1; spec.tile_depth = 1; if (header->hasTileDescription() && Strutil::icontains(header->type(), "tile")) { const Imf::TileDescription &td (header->tileDescription()); spec.tile_width = td.xSize; spec.tile_height = td.ySize; levelmode = td.mode; roundingmode = td.roundingMode; if (levelmode == Imf::MIPMAP_LEVELS) nmiplevels = numlevels (std::max(topwidth,topheight), roundingmode); else if (levelmode == Imf::RIPMAP_LEVELS) nmiplevels = numlevels (std::max(topwidth,topheight), roundingmode); else nmiplevels = 1; } else { spec.tile_width = 0; spec.tile_height = 0; levelmode = Imf::ONE_LEVEL; nmiplevels = 1; } query_channels (header); // also sets format spec.deep = Strutil::istarts_with (header->type(), "deep"); // Unless otherwise specified, exr files are assumed to be linear. spec.attribute ("oiio:ColorSpace", "Linear"); if (levelmode != Imf::ONE_LEVEL) spec.attribute ("openexr:roundingmode", roundingmode); const Imf::EnvmapAttribute *envmap; envmap = header->findTypedAttribute<Imf::EnvmapAttribute>("envmap"); if (envmap) { cubeface = (envmap->value() == Imf::ENVMAP_CUBE); spec.attribute ("textureformat", cubeface ? "CubeFace Environment" : "LatLong Environment"); // OpenEXR conventions for env maps if (! cubeface) spec.attribute ("oiio:updirection", "y"); spec.attribute ("oiio:sampleborder", 1); // FIXME - detect CubeFace Shadow? } else { cubeface = false; if (spec.tile_width && levelmode == Imf::MIPMAP_LEVELS) spec.attribute ("textureformat", "Plain Texture"); // FIXME - detect Shadow } const Imf::CompressionAttribute *compressattr; compressattr = header->findTypedAttribute<Imf::CompressionAttribute>("compression"); if (compressattr) { const char *comp = NULL; switch (compressattr->value()) { case Imf::NO_COMPRESSION : comp = "none"; break; case Imf::RLE_COMPRESSION : comp = "rle"; break; case Imf::ZIPS_COMPRESSION : comp = "zips"; break; case Imf::ZIP_COMPRESSION : comp = "zip"; break; case Imf::PIZ_COMPRESSION : comp = "piz"; break; case Imf::PXR24_COMPRESSION : comp = "pxr24"; break; #ifdef IMF_B44_COMPRESSION // The enum Imf::B44_COMPRESSION is not defined in older versions // of OpenEXR, and there are no explicit version numbers in the // headers. BUT this other related #define is present only in // the newer version. case Imf::B44_COMPRESSION : comp = "b44"; break; case Imf::B44A_COMPRESSION : comp = "b44a"; break; #endif #if defined(OPENEXR_VERSION_MAJOR) && \ (OPENEXR_VERSION_MAJOR*10000+OPENEXR_VERSION_MINOR*100+OPENEXR_VERSION_PATCH) >= 20200 case Imf::DWAA_COMPRESSION : comp = "dwaa"; break; case Imf::DWAB_COMPRESSION : comp = "dwab"; break; #endif default: break; } if (comp) spec.attribute ("compression", comp); } for (Imf::Header::ConstIterator hit = header->begin(); hit != header->end(); ++hit) { const Imf::IntAttribute *iattr; const Imf::FloatAttribute *fattr; const Imf::StringAttribute *sattr; const Imf::M33fAttribute *m33fattr; const Imf::M44fAttribute *m44fattr; const Imf::V3fAttribute *v3fattr; const Imf::V3iAttribute *v3iattr; const Imf::V2fAttribute *v2fattr; const Imf::V2iAttribute *v2iattr; const Imf::Box2iAttribute *b2iattr; const Imf::Box2fAttribute *b2fattr; const Imf::TimeCodeAttribute *tattr; const Imf::KeyCodeAttribute *kcattr; const Imf::ChromaticitiesAttribute *crattr; const Imf::RationalAttribute *rattr; const Imf::StringVectorAttribute *svattr; const Imf::DoubleAttribute *dattr; const Imf::V2dAttribute *v2dattr; const Imf::V3dAttribute *v3dattr; const Imf::M33dAttribute *m33dattr; const Imf::M44dAttribute *m44dattr; const char *name = hit.name(); std::string oname = exr_tag_to_oiio_std[name]; if (oname.empty()) // Empty string means skip this attrib continue; // if (oname == name) // oname = std::string(format_name()) + "_" + oname; const Imf::Attribute &attrib = hit.attribute(); std::string type = attrib.typeName(); if (type == "string" && (sattr = header->findTypedAttribute<Imf::StringAttribute> (name))) spec.attribute (oname, sattr->value().c_str()); else if (type == "int" && (iattr = header->findTypedAttribute<Imf::IntAttribute> (name))) spec.attribute (oname, iattr->value()); else if (type == "float" && (fattr = header->findTypedAttribute<Imf::FloatAttribute> (name))) spec.attribute (oname, fattr->value()); else if (type == "m33f" && (m33fattr = header->findTypedAttribute<Imf::M33fAttribute> (name))) spec.attribute (oname, TypeMatrix33, &(m33fattr->value())); else if (type == "m44f" && (m44fattr = header->findTypedAttribute<Imf::M44fAttribute> (name))) spec.attribute (oname, TypeMatrix44, &(m44fattr->value())); else if (type == "v3f" && (v3fattr = header->findTypedAttribute<Imf::V3fAttribute> (name))) spec.attribute (oname, TypeVector, &(v3fattr->value())); else if (type == "v3i" && (v3iattr = header->findTypedAttribute<Imf::V3iAttribute> (name))) { TypeDesc v3 (TypeDesc::INT, TypeDesc::VEC3, TypeDesc::VECTOR); spec.attribute (oname, v3, &(v3iattr->value())); } else if (type == "v2f" && (v2fattr = header->findTypedAttribute<Imf::V2fAttribute> (name))) { TypeDesc v2 (TypeDesc::FLOAT,TypeDesc::VEC2); spec.attribute (oname, v2, &(v2fattr->value())); } else if (type == "v2i" && (v2iattr = header->findTypedAttribute<Imf::V2iAttribute> (name))) { TypeDesc v2 (TypeDesc::INT,TypeDesc::VEC2); spec.attribute (oname, v2, &(v2iattr->value())); } else if (type == "stringvector" && (svattr = header->findTypedAttribute<Imf::StringVectorAttribute> (name))) { std::vector<std::string> strvec = svattr->value(); std::vector<ustring> ustrvec (strvec.size()); for (size_t i = 0, e = strvec.size(); i < e; ++i) ustrvec[i] = strvec[i]; TypeDesc sv (TypeDesc::STRING, ustrvec.size()); spec.attribute(oname, sv, &ustrvec[0]); } else if (type == "double" && (dattr = header->findTypedAttribute<Imf::DoubleAttribute> (name))) { TypeDesc d (TypeDesc::DOUBLE); spec.attribute (oname, d, &(dattr->value())); } else if (type == "v2d" && (v2dattr = header->findTypedAttribute<Imf::V2dAttribute> (name))) { TypeDesc v2 (TypeDesc::DOUBLE,TypeDesc::VEC2); spec.attribute (oname, v2, &(v2dattr->value())); } else if (type == "v3d" && (v3dattr = header->findTypedAttribute<Imf::V3dAttribute> (name))) { TypeDesc v3 (TypeDesc::DOUBLE,TypeDesc::VEC3, TypeDesc::VECTOR); spec.attribute (oname, v3, &(v3dattr->value())); } else if (type == "m33d" && (m33dattr = header->findTypedAttribute<Imf::M33dAttribute> (name))) { TypeDesc m33 (TypeDesc::DOUBLE, TypeDesc::MATRIX33); spec.attribute (oname, m33, &(m33dattr->value())); } else if (type == "m44d" && (m44dattr = header->findTypedAttribute<Imf::M44dAttribute> (name))) { TypeDesc m44 (TypeDesc::DOUBLE, TypeDesc::MATRIX44); spec.attribute (oname, m44, &(m44dattr->value())); } else if (type == "box2i" && (b2iattr = header->findTypedAttribute<Imf::Box2iAttribute> (name))) { TypeDesc bx (TypeDesc::INT, TypeDesc::VEC2, 2); spec.attribute (oname, bx, &b2iattr->value()); } else if (type == "box2f" && (b2fattr = header->findTypedAttribute<Imf::Box2fAttribute> (name))) { TypeDesc bx (TypeDesc::FLOAT, TypeDesc::VEC2, 2); spec.attribute (oname, bx, &b2fattr->value()); } else if (type == "timecode" && (tattr = header->findTypedAttribute<Imf::TimeCodeAttribute> (name))) { unsigned int timecode[2]; timecode[0] = tattr->value().timeAndFlags(Imf::TimeCode::TV60_PACKING); //TV60 returns unchanged _time timecode[1] = tattr->value().userData(); // Elevate "timeCode" to smpte:TimeCode if (oname == "timeCode") oname = "smpte:TimeCode"; spec.attribute(oname, TypeTimeCode, timecode); } else if (type == "keycode" && (kcattr = header->findTypedAttribute<Imf::KeyCodeAttribute> (name))) { const Imf::KeyCode *k = &kcattr->value(); unsigned int keycode[7]; keycode[0] = k->filmMfcCode(); keycode[1] = k->filmType(); keycode[2] = k->prefix(); keycode[3] = k->count(); keycode[4] = k->perfOffset(); keycode[5] = k->perfsPerFrame(); keycode[6] = k->perfsPerCount(); // Elevate "keyCode" to smpte:KeyCode if (oname == "keyCode") oname = "smpte:KeyCode"; spec.attribute(oname, TypeKeyCode, keycode); } else if (type == "chromaticities" && (crattr = header->findTypedAttribute<Imf::ChromaticitiesAttribute> (name))) { const Imf::Chromaticities *chroma = &crattr->value(); spec.attribute (oname, TypeDesc(TypeDesc::FLOAT,8), (const float *)chroma); } else if (type == "rational" && (rattr = header->findTypedAttribute<Imf::RationalAttribute> (name))) { const Imf::Rational *rational = &rattr->value(); int n = rational->n; unsigned int d = rational->d; if (d < (1UL << 31)) { int r[2]; r[0] = n; r[1] = static_cast<int>(d); spec.attribute (oname, TypeRational, r); } else if (int f = static_cast<int>(boost::math::gcd<long int>(rational[0], rational[1])) > 1) { int r[2]; r[0] = n / f; r[1] = static_cast<int>(d / f); spec.attribute (oname, TypeRational, r); } else { // TODO: find a way to allow the client to accept "close" rational values OIIO::debug ("Don't know what to do with OpenEXR Rational attribute %s with value %d / %u that we cannot represent exactly", oname, n, d); } } else { #if 0 std::cerr << " unknown attribute " << type << ' ' << name << "\n"; #endif } } float aspect = spec.get_float_attribute ("PixelAspectRatio", 0.0f); float xdensity = spec.get_float_attribute ("XResolution", 0.0f); if (xdensity) { // If XResolution is found, supply the YResolution and unit. spec.attribute ("YResolution", xdensity * (aspect ? aspect : 1.0f)); spec.attribute ("ResolutionUnit", "in"); // EXR is always pixels/inch } // EXR "name" also gets passed along as "oiio:subimagename". if (header->hasName()) spec.attribute ("oiio:subimagename", header->name()); // Squash some problematic texture metadata if we suspect it's wrong pvt::check_texture_metadata_sanity (spec); initialized = true; }
//-------------------------------------------------------------- void ofApp::draw(){ if (path_est.size() > 0) { cam.begin(); ofPushStyle(); /// Render points as 3D cubes for (size_t i = 0; i < point_cloud_est.size(); ++i) { cv::Vec3d point = point_cloud_est[i]; cv::Affine3d point_pose(cv::Mat::eye(3, 3, CV_64F), point); char buffer[50]; sprintf(buffer, "%d", static_cast<int>(i)); ofBoxPrimitive box; ofSetLineWidth(2.0f); ofSetColor(ofColor::blue); box.set(0.1, 0.1, -0.1); box.setPosition(point[0], point[1], point[2]); box.drawWireframe(); } ofPopStyle(); cam.end(); cv::Affine3d cam_pose = path_est[idx]; cv::Matx44d mat44 = cam_pose.matrix; ofMatrix4x4 m44(mat44(0, 0), mat44(1, 0), mat44(2, 0), mat44(3, 0), mat44(0, 1), mat44(1, 1), mat44(2, 1), mat44(3, 1), mat44(0, 2), mat44(1, 2), mat44(2, 2), mat44(3, 2), mat44(0, 3), mat44(1, 3), mat44(2, 3), mat44(3, 3)); if (camera_pov) { cam.setPosition(m44.getTranslation()); cam.lookAt(ofVec3f(0,0,1)*m44, ofVec3f(mat44(1,0),mat44(1,1), mat44(1,2))); } else { std::vector<ofPoint> path; for (int i = 0; i < path_est.size()-1; i++) { cv::Vec3d point = path_est[i].translation(); path.push_back(ofPoint(point[0], point[1], point[2])); } ofPolyline trajectory(path); // render complete trajectory cam.begin(); ofSetColor(ofColor::green); trajectory.draw(); ofSetColor(ofColor::yellow); ofPushMatrix(); ofMultMatrix(m44); ofDrawAxis(0.25); drawFrustum(f, cx, cy, 0.025, 0.4); ofPopMatrix(); cam.end(); } // update trajectory index (spring effect) forw *= (idx == n-1 || idx == 0) ? -1 : 1; idx += forw; } }
inline void m43(UINT j) { m44 (j); d41 = j + 1; };