Skip to content

Instantly share code, notes, and snippets.

@satoruhiga
satoruhiga / Spherical coordinate
Created September 25, 2012 11:42
cartesianToSpherical / sphericalToCartesian
ofVec3f cartesianToSpherical(const ofVec3f &v)
{
float r = v.length();
float s = acos(v.z / r);
float f = atan2(v.y, v.x);
return ofVec3f(r, s, f);
}
ofVec3f sphericalToCartesian(const ofVec3f &v)
{
@satoruhiga
satoruhiga / type_2_int.cpp
Created September 11, 2012 22:24
Type2Int
template<typename T>
struct Type2Int
{
static unsigned int value()
{
static size_t m = 0;
return (unsigned int)&m;
}
};
@satoruhiga
satoruhiga / type_2_string.cpp
Created September 11, 2012 22:09
Type2String
template<typename T>
struct Type2String
{
static std::string value()
{
throw std::runtime_error("unregistered type");
}
};
#define REGISTER_TYPE(t) \
@satoruhiga
satoruhiga / text_util.h
Created May 22, 2012 12:58
text_util.h
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
namespace text_util
{
typedef std::map<std::string, std::string> param;
@satoruhiga
satoruhiga / testApp.cpp
Created January 27, 2012 06:13
image from base64 string
#include "testApp.h"
#include "Poco/Base64Decoder.h"
// # encodeing
// $ base64 openFrameworks.png
string base64ImageData = "iVBORw0KGgoAAAANSUhEUgAAAHIAAAA8CAYAAAC6j+5hAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sLGgwmJX2ZbqEAAAQrSURBVHja7Z2rdxtHFIe/34xspFO+f4BbXIXrD6hQkIMC2qAE1CygMbJBjWpSFhGjmoTJxRUpqniPeMXbZfHOLdjNqRw/9Kj2odm9TEBndefbO/cxd65kZrRVJD2r4DF/mdlC0hHwRUnP+FtVg5TUB74qPv5pZmldIHtyv5f/FHt/azb28j8LG5TwgDTDXvdKBHYEDBwMwPU/KeHR54uZq4tmENIAM2BmZnM6WQuimc17u4Z3gBsFbORRf+mtXP1dbADCw7AAnBr6LRCuO6hPQwTYCcie9A3olUdJYGdbdV/5CzHqyS2KLeqm43cfIoD7v8FCT+4D6BRISvzhCei0J/dB0rCDeBfi1hYpKXFw4ql8UROPLrz8LBDOzWzRQdzSIiUNPboS9VmGsIFHVy2zzkchbgzyUP7Eowug3wDF+h5dHMqftB3iRiC9/LuAHTdNw4Ade/l3EZct5hn2fFXk7taFKGzUWFWxkZeu4oQYXq9TNHH7DvE/mDqKyzLXh7gSZE/6bh8gLltmHD5zM4hPgswLynq1b0sQsOP9jmY3h/goSEl9j37c16Xw6FRS0haIj4J0cNqQFGPr1MTBSVsgPghS0rM6k/0dBj/Dis4ba4f4IEgH38cS93n0Qxsg3gNZWONRRIlYkp/MxA3xHkiH+za2lNrgRewQ74CUlJTUilB7oaDoVogW4h2QB7hjIpUD3ChmiHdABizaI6Hm6FYORCgOliUlnn1MoNcPeiQldR5EizDJ
@satoruhiga
satoruhiga / loadObj.h
Created January 10, 2012 11:19
load .obj file
#pragma once
#include "ofMain.h"
bool loadObj(string path, ofMesh &mesh, ofImage *tex = NULL)
{
path = ofToDataPath(path);
if (!ofFile::doesFileExist(path)) return false;
ifstream ifs(path.c_str());
@satoruhiga
satoruhiga / cvFlannTest.cpp
Created December 26, 2011 07:45
cvFlannTest.cpp
#include "testApp.h"
#include "ofxCv.h"
using namespace ofxCv;
using namespace cv;
#include <opencv2/flann/flann.hpp>
ofMesh mesh;
@satoruhiga
satoruhiga / cstringify.py
Created December 15, 2011 06:50
cstringify.py
#/usr/bin/env python
import sys, os
if len(sys.argv) is not 2:
print 'usage: ./cstringify.py [FILENAME]'
sys.exit(-1)
filename = sys.argv[1]
@satoruhiga
satoruhiga / readDepthPixelsToImage.h
Created December 11, 2011 12:38
readDepthPixelsToImage
void readDepthPixelsToImage(ofFloatImage &image)
{
glPopAttrib();
glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT );
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, image.getWidth(), image.getHeight(), GL_DEPTH_COMPONENT, GL_FLOAT, image.getPixels());
glPopClientAttrib();
image.update();
}
@satoruhiga
satoruhiga / homography2glModelViewMatrix.h
Created December 5, 2011 08:45
homography2glModelViewMatrix
inline ofMatrix4x4 homography2glModelViewMatrix(const cv::Mat &homography)
{
ofMatrix4x4 matrix;
matrix(0, 0) = homography.at<double>(0, 0);
matrix(0, 1) = homography.at<double>(1, 0);
matrix(0, 2) = 0;
matrix(0, 3) = homography.at<double>(2, 0);
matrix(1, 0) = homography.at<double>(0, 1);