Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tunit.h"
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Toshihiro Shimizu 890ddd
#include <math.h></math.h>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Note: convertTo() means: convert from standard unit TO specific unit
Toshihiro Shimizu 890ddd
// e.g. if unit=cm (standard=inch) then convertTo(1) == 2.54
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
class VerticalCameraFldUnitConverter : public TUnitConverter {
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
  static double m_factor;
Toshihiro Shimizu 890ddd
  VerticalCameraFldUnitConverter() {}
Toshihiro Shimizu 890ddd
  TUnitConverter * clone() const {return new VerticalCameraFldUnitConverter(*this);}
Toshihiro Shimizu 890ddd
  double convertTo(double v) const {return v*m_factor;}
Toshihiro Shimizu 890ddd
  double convertFrom(double v) const {return v/m_factor;}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double VerticalCameraFldUnitConverter::m_factor = 1;
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace UnitParameters
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
std::pair<double, double=""> dummyCurrentDpiGetter() { return std::make_pair<double, double="">(72, 72); }</double,></double,>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
CurrentDpiGetter currentDpiGetter = &dummyCurrentDpiGetter;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void setCurrentDpiGetter(CurrentDpiGetter f) { currentDpiGetter = f; }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class VerticalFldUnitConverter : public TUnitConverter
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double m_factor;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	static double m_fieldGuideAspectRatio;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	VerticalFldUnitConverter(double factor) : m_factor(factor) {}
Toshihiro Shimizu 890ddd
	TUnitConverter *clone() const { return new VerticalFldUnitConverter(*this); }
Toshihiro Shimizu 890ddd
	double convertTo(double v) const { return v * m_fieldGuideAspectRatio * m_factor; }
Toshihiro Shimizu 890ddd
	double convertFrom(double v) const { return v / (m_fieldGuideAspectRatio * m_factor); }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
double VerticalFldUnitConverter::m_fieldGuideAspectRatio = 1.38;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace UnitParameters
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void setFieldGuideAspectRatio(double ar)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(ar > 0);
Toshihiro Shimizu 890ddd
	VerticalFldUnitConverter::m_fieldGuideAspectRatio = ar;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double getFieldGuideAspectRatio()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return VerticalFldUnitConverter::m_fieldGuideAspectRatio;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TangentConverter : public TUnitConverter
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TangentConverter() {}
Toshihiro Shimizu 890ddd
	TUnitConverter *clone() const { return new TangentConverter(*this); }
Toshihiro Shimizu 890ddd
	double convertTo(double v) const { return 180.0 * atan(v) / TConsts::pi; }
Toshihiro Shimizu 890ddd
	double convertFrom(double v) const { return tan(TConsts::pi * v / 180.0); }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TPixelUnitXConverter : public TUnitConverter
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TPixelUnitXConverter() {}
Toshihiro Shimizu 890ddd
	TUnitConverter *clone() const { return new TPixelUnitXConverter(*this); }
Toshihiro Shimizu 890ddd
	double convertTo(double v) const { return v * UnitParameters::currentDpiGetter().first; }
Toshihiro Shimizu 890ddd
	double convertFrom(double v) const { return v / UnitParameters::currentDpiGetter().first; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TPixelUnitYConverter : public TUnitConverter
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TPixelUnitYConverter() {}
Toshihiro Shimizu 890ddd
	TUnitConverter *clone() const { return new TPixelUnitYConverter(*this); }
Toshihiro Shimizu 890ddd
	double convertTo(double v) const { return v * UnitParameters::currentDpiGetter().second; }
Toshihiro Shimizu 890ddd
	double convertFrom(double v) const { return v / UnitParameters::currentDpiGetter().second; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
TUnit::TUnit(std::wstring ext, TUnitConverter *converter)
Toshihiro Shimizu 890ddd
	: m_defaultExtension(ext), m_converter(converter)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_extensions.push_back(ext);
Toshihiro Shimizu 890ddd
	if (m_converter == 0)
Toshihiro Shimizu 890ddd
		m_converter = new TSimpleUnitConverter();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TUnit::TUnit(const TUnit &src)
Toshihiro Shimizu 890ddd
	: m_defaultExtension(src.m_defaultExtension), m_extensions(src.m_extensions), m_converter(src.m_converter->clone())
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TUnit::~TUnit()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	delete m_converter;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
void TUnit::addExtension(std::wstring ext)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (std::find(
Toshihiro Shimizu 890ddd
			m_extensions.begin(), m_extensions.end(), ext) == m_extensions.end())
Toshihiro Shimizu 890ddd
		m_extensions.push_back(ext);
Toshihiro Shimizu 890ddd
	if (m_defaultExtension.empty())
Toshihiro Shimizu 890ddd
		m_defaultExtension = ext;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
bool TUnit::isExtension(std::wstring ext) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return std::find(
Toshihiro Shimizu 890ddd
			   m_extensions.begin(), m_extensions.end(), ext) != m_extensions.end();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
void TUnit::setDefaultExtension(std::wstring ext)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!ext.empty() && std::find(m_extensions.begin(), m_extensions.end(), ext) == m_extensions.end())
Toshihiro Shimizu 890ddd
		m_extensions.push_back(ext);
Toshihiro Shimizu 890ddd
	m_defaultExtension = ext;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
TMeasure::TMeasure(std::string name, TUnit *mainUnit)
Toshihiro Shimizu 890ddd
	: m_name(name), m_mainUnit(0), m_standardUnit(0), m_currentUnit(0), m_defaultValue(0)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	add(mainUnit);
Toshihiro Shimizu 890ddd
	m_mainUnit = m_currentUnit = m_standardUnit = mainUnit;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TMeasure::TMeasure(const TMeasure &src)
Toshihiro Shimizu 890ddd
	: m_name(src.m_name), m_mainUnit(src.m_mainUnit), m_currentUnit(src.m_currentUnit), m_standardUnit(src.m_standardUnit), m_defaultValue(src.m_defaultValue)
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 3bfa54
	std::map<std::wstring, *="" tunit="">::const_iterator it;</std::wstring,>
Toshihiro Shimizu 890ddd
	for (it = src.m_extensions.begin();
Toshihiro Shimizu 890ddd
		 it != src.m_extensions.end(); ++it) {
Toshihiro Shimizu 890ddd
		TUnit *u = it->second;
Toshihiro Shimizu 890ddd
		assert(u);
Shinya Kitaoka 3bfa54
		const std::vector<std::wstring> &e = u->getExtensions();</std::wstring>
Toshihiro Shimizu 890ddd
		assert(std::find(e.begin(), e.end(), it->first) != e.end());
Toshihiro Shimizu 890ddd
		m_extensions[it->first] = u;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TMeasure::~TMeasure()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TMeasure::add(TUnit *unit)
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 3bfa54
	const std::vector<std::wstring> &e = unit->getExtensions();</std::wstring>
Toshihiro Shimizu 890ddd
	for (int i = 0; i < (int)e.size(); i++) {
Shinya Kitaoka 3bfa54
		std::wstring ext = e[i];
Toshihiro Shimizu 890ddd
		assert(m_extensions.count(ext) == 0);
Toshihiro Shimizu 890ddd
		m_extensions[ext] = unit;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
TUnit *TMeasure::getUnit(std::wstring ext) const
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 3bfa54
	std::map<std::wstring, *="" tunit="">::const_iterator it;</std::wstring,>
Toshihiro Shimizu 890ddd
	it = m_extensions.find(ext);
Toshihiro Shimizu 890ddd
	return it == m_extensions.end() ? 0 : it->second;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TMeasure::setCurrentUnit(TUnit *unit)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(unit);
Toshihiro Shimizu 890ddd
	assert(m_extensions.count(unit->getDefaultExtension()) > 0);
Toshihiro Shimizu 890ddd
	m_currentUnit = unit;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TMeasure::setStandardUnit(TUnit *unit)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(unit);
Toshihiro Shimizu 890ddd
	assert(m_extensions.count(unit->getDefaultExtension()) > 0);
Toshihiro Shimizu 890ddd
	m_standardUnit = unit;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TMeasureManager::TMeasureManager()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TUnit
Toshihiro Shimizu 890ddd
		inch(L"in"),
Toshihiro Shimizu 890ddd
		cm(L"cm", new TSimpleUnitConverter(2.54)),
Toshihiro Shimizu 890ddd
		mm(L"mm", new TSimpleUnitConverter(25.4)),
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		xfld(L"fld", new TSimpleUnitConverter(2)),
Toshihiro Shimizu 890ddd
		cameraXFld(L"fld", new TSimpleUnitConverter(1)),
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		yfld(L"fld", new VerticalFldUnitConverter(2)),
Toshihiro Shimizu 890ddd
		cameraYFld(L"fld", new VerticalFldUnitConverter(1)),
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		levelXFld(L"fld", new TSimpleUnitConverter(1)),
Toshihiro Shimizu 890ddd
		levelYFld(L"fld", new VerticalFldUnitConverter(1)),
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		internalZDepth(L"internal.zdepth"),
Toshihiro Shimizu 890ddd
		zdepth(L"zdepth", new TSimpleUnitConverter(1)),
Toshihiro Shimizu 890ddd
		degree(L"\u00b0"),
Toshihiro Shimizu 890ddd
		scale(L"*"),
Toshihiro Shimizu 890ddd
		percentage2(L"%"),
Toshihiro Shimizu 890ddd
		shear(L"sh"),
Toshihiro Shimizu 890ddd
		shearAngle(L"\u00b0", new TangentConverter()),
Toshihiro Shimizu 890ddd
		percentage(L"%", new TSimpleUnitConverter(100)),
Toshihiro Shimizu 890ddd
		colorChannel(L"", new TSimpleUnitConverter(255)),
Toshihiro Shimizu 890ddd
		dummy(L""),
Toshihiro Shimizu 890ddd
		xPixel(L"px", new TPixelUnitXConverter()),
Toshihiro Shimizu 890ddd
		yPixel(L"px", new TPixelUnitYConverter());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	inch.addExtension(L"inch");
Toshihiro Shimizu 890ddd
	inch.addExtension(L"\"");
Toshihiro Shimizu 890ddd
	inch.addExtension(L"''");
Toshihiro Shimizu 890ddd
	inch.setDefaultExtension(L"\"");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	xPixel.addExtension(L"pixel");
Toshihiro Shimizu 890ddd
	yPixel.addExtension(L"pixel");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	xfld.addExtension(L"field");
Toshihiro Shimizu 890ddd
	cameraXFld.addExtension(L"field");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	yfld.addExtension(L"field");
Toshihiro Shimizu 890ddd
	cameraYFld.addExtension(L"field");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	levelXFld.addExtension(L"field");
Toshihiro Shimizu 890ddd
	levelYFld.addExtension(L"field");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	xfld.addExtension(L"F");
Toshihiro Shimizu 890ddd
	yfld.addExtension(L"F");
Toshihiro Shimizu 890ddd
	cameraXFld.addExtension(L"F");
Toshihiro Shimizu 890ddd
	cameraYFld.addExtension(L"F");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	levelXFld.addExtension(L"F");
Toshihiro Shimizu 890ddd
	levelYFld.addExtension(L"F");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TMeasure *length, *m;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	length = m = new TMeasure("length", inch.clone());
Toshihiro Shimizu 890ddd
	m->add(cm.clone());
Toshihiro Shimizu 890ddd
	/*---
Toshihiro Shimizu 890ddd
	Fxの寸法パラメータは単位なし(実際にはStageInch(1 StageInch = 1/53.33333 inch)という値)
Toshihiro Shimizu 890ddd
	Fxの寸法パラメータからExpressionで単位のあるパラメータを参照すると、
Toshihiro Shimizu 890ddd
	カレントUnitによってFxの計算結果が変わってしまう。
Toshihiro Shimizu 890ddd
	tcomposerで用いられるカレントUnitはデフォルト値なので、
Toshihiro Shimizu 890ddd
	ここでデフォルトのカレントUnitをmmにしておくことで、
Toshihiro Shimizu 890ddd
	Unit = mm でシーンを作っておけば、作業時と同じRender結果が得られるようにする。
Toshihiro Shimizu 890ddd
	---*/
Toshihiro Shimizu 890ddd
	TUnit *mmUnit = mm.clone();
Toshihiro Shimizu 890ddd
	m->add(mmUnit);
Toshihiro Shimizu 890ddd
	m->setCurrentUnit(mmUnit);
Toshihiro Shimizu 890ddd
	add(m);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m = new TMeasure(*length);
Toshihiro Shimizu 890ddd
	m->setName("length.x");
Toshihiro Shimizu 890ddd
	m->add(xfld.clone());
Toshihiro Shimizu 890ddd
	m->add(xPixel.clone());
Toshihiro Shimizu 890ddd
	add(m);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m = new TMeasure(*length);
Toshihiro Shimizu 890ddd
	m->setName("length.y");
Toshihiro Shimizu 890ddd
	m->add(yfld.clone());
Toshihiro Shimizu 890ddd
	m->add(yPixel.clone());
Toshihiro Shimizu 890ddd
	add(m);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m = new TMeasure(*length);
Toshihiro Shimizu 890ddd
	m->setName("length.lx");
Toshihiro Shimizu 890ddd
	m->add(xfld.clone());
Toshihiro Shimizu 890ddd
	m->add(xPixel.clone());
Toshihiro Shimizu 890ddd
	add(m);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m = new TMeasure(*length);
Toshihiro Shimizu 890ddd
	m->setName("length.ly");
Toshihiro Shimizu 890ddd
	m->add(yfld.clone());
Toshihiro Shimizu 890ddd
	m->add(yPixel.clone());
Toshihiro Shimizu 890ddd
	add(m);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m = new TMeasure(*length);
Toshihiro Shimizu 890ddd
	m->setName("camera.lx");
Toshihiro Shimizu 890ddd
	m->add(cameraXFld.clone());
Toshihiro Shimizu 890ddd
	m->add(xPixel.clone());
Toshihiro Shimizu 890ddd
	add(m);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m = new TMeasure(*length);
Toshihiro Shimizu 890ddd
	m->setName("camera.ly");
Toshihiro Shimizu 890ddd
	m->add(cameraYFld.clone());
Toshihiro Shimizu 890ddd
	m->add(yPixel.clone());
Toshihiro Shimizu 890ddd
	add(m);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m = new TMeasure(*length);
Toshihiro Shimizu 890ddd
	m->setName("level.lx");
Toshihiro Shimizu 890ddd
	m->add(levelXFld.clone());
Toshihiro Shimizu 890ddd
	add(m);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m = new TMeasure(*length);
Toshihiro Shimizu 890ddd
	m->setName("level.ly");
Toshihiro Shimizu 890ddd
	m->add(levelYFld.clone());
Toshihiro Shimizu 890ddd
	add(m);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m = new TMeasure(*length);
Toshihiro Shimizu 890ddd
	m->setName("canvas.lx");
Toshihiro Shimizu 890ddd
	m->add(cameraXFld.clone());
Toshihiro Shimizu 890ddd
	add(m);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m = new TMeasure(*length);
Toshihiro Shimizu 890ddd
	m->setName("canvas.ly");
Toshihiro Shimizu 890ddd
	m->add(cameraYFld.clone());
Toshihiro Shimizu 890ddd
	add(m);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TUnit fxLength(L"fxLength"),
Toshihiro Shimizu 890ddd
		fxInch(L"in", new TSimpleUnitConverter(1 / 53.33333)),
Toshihiro Shimizu 890ddd
		fxCm(L"cm", new TSimpleUnitConverter(2.54 / 53.33333)),
Toshihiro Shimizu 890ddd
		fxMm(L"mm", new TSimpleUnitConverter(25.4 / 53.33333)),
Toshihiro Shimizu 890ddd
		fxXfld(L"fld", new TSimpleUnitConverter(2 / 53.33333));
Toshihiro Shimizu 890ddd
	fxInch.addExtension(L"inch");
Toshihiro Shimizu 890ddd
	fxInch.addExtension(L"\"");
Toshihiro Shimizu 890ddd
	fxInch.addExtension(L"''");
Toshihiro Shimizu 890ddd
	fxInch.setDefaultExtension(L"\"");
Toshihiro Shimizu 890ddd
	fxXfld.addExtension(L"field");
Toshihiro Shimizu 890ddd
	fxXfld.addExtension(L"F");
Toshihiro Shimizu 890ddd
	m = new TMeasure("fxLength", fxLength.clone());
Toshihiro Shimizu 890ddd
	m->add(fxInch.clone());
Toshihiro Shimizu 890ddd
	m->add(fxCm.clone());
Toshihiro Shimizu 890ddd
	m->add(fxMm.clone());
Toshihiro Shimizu 890ddd
	m->add(fxXfld.clone());
Toshihiro Shimizu 890ddd
	add(m);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m = new TMeasure("angle", degree.clone());
Toshihiro Shimizu 890ddd
	add(m);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m = new TMeasure("scale", scale.clone());
Toshihiro Shimizu 890ddd
	TUnit *unit = percentage.clone();
Toshihiro Shimizu 890ddd
	m->add(unit);
Toshihiro Shimizu 890ddd
	m->setCurrentUnit(unit);
Toshihiro Shimizu 890ddd
	m->setStandardUnit(unit);
Toshihiro Shimizu 890ddd
	add(m);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m = new TMeasure("percentage", scale.clone());
Toshihiro Shimizu 890ddd
	unit = percentage.clone();
Toshihiro Shimizu 890ddd
	m->add(unit);
Toshihiro Shimizu 890ddd
	m->setCurrentUnit(unit);
Toshihiro Shimizu 890ddd
	m->setStandardUnit(unit);
Toshihiro Shimizu 890ddd
	add(m);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m = new TMeasure("percentage2", percentage2.clone());
Toshihiro Shimizu 890ddd
	add(m);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m = new TMeasure("shear", shear.clone());
Toshihiro Shimizu 890ddd
	unit = shearAngle.clone();
Toshihiro Shimizu 890ddd
	m->add(unit);
Toshihiro Shimizu 890ddd
	m->setCurrentUnit(unit);
Toshihiro Shimizu 890ddd
	m->setStandardUnit(unit);
Toshihiro Shimizu 890ddd
	add(m);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m = new TMeasure("colorChannel", colorChannel.clone());
Toshihiro Shimizu 890ddd
	add(m);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*
Toshihiro Shimizu 890ddd
  m = new TMeasure("zdepth", internalZDepth.clone());
Toshihiro Shimizu 890ddd
  unit = zdepth.clone();
Toshihiro Shimizu 890ddd
  m->add(unit);
Toshihiro Shimizu 890ddd
  m->setCurrentUnit(unit);
Toshihiro Shimizu 890ddd
  m->setStandardUnit(unit);
Toshihiro Shimizu 890ddd
  add(m);
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
	m = new TMeasure("dummy", dummy.clone());
Toshihiro Shimizu 890ddd
	add(m);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TMeasureManager::add(TMeasure *m)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_measures[m->getName()] = m;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
TMeasure *TMeasureManager::get(std::string name) const
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 3bfa54
	std::map<std::string, *="" tmeasure="">::const_iterator it;</std::string,>
Toshihiro Shimizu 890ddd
	it = m_measures.find(name);
Toshihiro Shimizu 890ddd
	if (it == m_measures.end())
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		return it->second;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
TMeasuredValue::TMeasuredValue(std::string measureName)
Toshihiro Shimizu 890ddd
	: m_measure(0), m_value(0)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setMeasure(measureName);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TMeasuredValue::~TMeasuredValue()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TMeasuredValue::setMeasure(const TMeasure *measure)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(measure);
Toshihiro Shimizu 890ddd
	if (!measure)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_measure = measure;
Toshihiro Shimizu 890ddd
	m_value = m_measure->getDefaultValue();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
void TMeasuredValue::setMeasure(std::string measureName)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setMeasure(TMeasureManager::instance()->get(measureName));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
bool TMeasuredValue::setValue(std::wstring s, int *pErr)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (s == ::toWideString("")) {
Toshihiro Shimizu 890ddd
		if (pErr)
Toshihiro Shimizu 890ddd
			*pErr = -1;
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	const TUnit *unit = m_measure->getCurrentUnit();
Toshihiro Shimizu 890ddd
	double value = 0;
Toshihiro Shimizu 890ddd
	bool valueFlag = false;
Toshihiro Shimizu 890ddd
	int i = 0, len = s.length();
Toshihiro Shimizu 890ddd
	// skip blanks
Toshihiro Shimizu 890ddd
	i = s.find_first_not_of(::toWideString(" \t"));
Shinya Kitaoka 3bfa54
	assert(i != (int)std::wstring::npos);
Toshihiro Shimizu 890ddd
	int j = i;
Toshihiro Shimizu 890ddd
	// match number
Toshihiro Shimizu 890ddd
	if (i < len && (s[i] == L'-' || s[i] == L'+'))
Toshihiro Shimizu 890ddd
		i++;
Toshihiro Shimizu 890ddd
	while (i < len && L'0' <= s[i] && s[i] <= L'9')
Toshihiro Shimizu 890ddd
		i++;
Toshihiro Shimizu 890ddd
	if (i < len && s[i] == L'.') {
Toshihiro Shimizu 890ddd
		i++;
Toshihiro Shimizu 890ddd
		while (i < len && L'0' <= s[i] && s[i] <= L'9')
Toshihiro Shimizu 890ddd
			i++;
Toshihiro Shimizu 890ddd
		if (i < len && (s[i] == L'E' || s[i] == L'e')) {
Toshihiro Shimizu 890ddd
			i++;
Toshihiro Shimizu 890ddd
			if (i < len && (s[i] == L'-' || s[i] == L'+'))
Toshihiro Shimizu 890ddd
				i++;
Toshihiro Shimizu 890ddd
			while (i < len && L'0' <= s[i] && s[i] <= L'9')
Toshihiro Shimizu 890ddd
				i++;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (i > j) {
Toshihiro Shimizu 890ddd
		value = toDouble(s.substr(j, i - j));
Toshihiro Shimizu 890ddd
		valueFlag = true;
Toshihiro Shimizu 890ddd
		// skip blanks
Toshihiro Shimizu 890ddd
		i = s.find_first_not_of(::toWideString(" \t"), i);
Shinya Kitaoka 3bfa54
		if (i == (int)std::wstring::npos)
Toshihiro Shimizu 890ddd
			i = s.length();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// remove trailing blanks
Toshihiro Shimizu 890ddd
	if (i < (int)s.length()) {
Toshihiro Shimizu 890ddd
		j = i;
Toshihiro Shimizu 890ddd
		i = s.find_last_not_of(::toWideString(" \t"));
Shinya Kitaoka 3bfa54
		if (i == (int)std::wstring::npos)
Toshihiro Shimizu 890ddd
			i = len - 1;
Toshihiro Shimizu 890ddd
		if (j <= i) {
Shinya Kitaoka 3bfa54
			std::wstring unitExt = s.substr(j, i + 1 - j);
Toshihiro Shimizu 890ddd
			unit = m_measure->getUnit(unitExt);
Toshihiro Shimizu 890ddd
			if (!unit) {
Toshihiro Shimizu 890ddd
				if (pErr)
Toshihiro Shimizu 890ddd
					*pErr = -2;
Toshihiro Shimizu 890ddd
				return false;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (valueFlag) {
Toshihiro Shimizu 890ddd
		double newValue = unit->convertFrom(value);
Toshihiro Shimizu 890ddd
		if (m_value == newValue) {
Toshihiro Shimizu 890ddd
			if (pErr)
Toshihiro Shimizu 890ddd
				*pErr = 0;
Toshihiro Shimizu 890ddd
			return false;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		m_value = newValue;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (pErr)
Toshihiro Shimizu 890ddd
		*pErr = (valueFlag || unit != 0) ? 0 : -3;
Toshihiro Shimizu 890ddd
	return valueFlag || unit != 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
std::wstring TMeasuredValue::toWideString(int decimals) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double v = getValue(CurrentUnit);
Shinya Kitaoka 3bfa54
	std::string s = toString(v, decimals);
Shinya Kitaoka 3bfa54
	if (s.find('.') != std::string::npos) {
Toshihiro Shimizu 890ddd
		int i = s.length();
Toshihiro Shimizu 890ddd
		while (i > 0 && s[i - 1] == '0')
Toshihiro Shimizu 890ddd
			i--;
Toshihiro Shimizu 890ddd
		if (i > 0 && s[i - 1] == '.')
Toshihiro Shimizu 890ddd
			i--;
Toshihiro Shimizu 890ddd
		if (i < (int)s.length())
Toshihiro Shimizu 890ddd
			s = s.substr(0, i);
Toshihiro Shimizu 890ddd
	}
Shinya Kitaoka 3bfa54
	std::wstring measure = m_measure->getCurrentUnit()->getDefaultExtension();
Toshihiro Shimizu 890ddd
	if (measure.empty())
Toshihiro Shimizu 890ddd
		return ::toWideString(s);
Toshihiro Shimizu 890ddd
	return ::toWideString(s) + ::toWideString(" ") + measure;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class ZDepthUnitConverter : public TUnitConverter
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TMeasureManager::CameraSizeProvider *m_cameraSizeProvider;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	ZDepthUnitConverter(TMeasureManager::CameraSizeProvider *cameraSizeProvider)
Toshihiro Shimizu 890ddd
		: m_cameraSizeProvider(cameraSizeProvider)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	TUnitConverter *clone() const { return new ZDepthUnitConverter(m_cameraSizeProvider); }
Toshihiro Shimizu 890ddd
	inline double getCameraSize() const { return (*m_cameraSizeProvider)(); }
Toshihiro Shimizu 890ddd
	double convertTo(double v) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return (1 - v * 0.001) * getCameraSize();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	double convertFrom(double v) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return (1 - v / getCameraSize()) * 1000.0;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class CameraZDepthUnitConverter : public TUnitConverter
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TMeasureManager::CameraSizeProvider *m_cameraSizeProvider;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	CameraZDepthUnitConverter(TMeasureManager::CameraSizeProvider *cameraSizeProvider)
Toshihiro Shimizu 890ddd
		: m_cameraSizeProvider(cameraSizeProvider)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	TUnitConverter *clone() const { return new CameraZDepthUnitConverter(m_cameraSizeProvider); }
Toshihiro Shimizu 890ddd
	inline double getCameraSize() const { return (*m_cameraSizeProvider)(); }
Toshihiro Shimizu 890ddd
	double convertTo(double v) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return (1 + v * 0.001) * getCameraSize();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	double convertFrom(double v) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return (v / getCameraSize() - 1) * 1000.0;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
/*-- Zのカーブのハンドルの長さは0=0となるようにしなければならない --*/
Toshihiro Shimizu 890ddd
class ZDepthHandleUnitConverter : public TUnitConverter
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TMeasureManager::CameraSizeProvider *m_cameraSizeProvider;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	ZDepthHandleUnitConverter(TMeasureManager::CameraSizeProvider *cameraSizeProvider)
Toshihiro Shimizu 890ddd
		: m_cameraSizeProvider(cameraSizeProvider)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TUnitConverter *clone() const { return new ZDepthHandleUnitConverter(m_cameraSizeProvider); }
Toshihiro Shimizu 890ddd
	inline double getCameraSize() const { return (*m_cameraSizeProvider)(); }
Toshihiro Shimizu 890ddd
	double convertTo(double v) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return -v * 0.001 * getCameraSize();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	double convertFrom(double v) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return (-v / getCameraSize()) * 1000.0;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class CameraZDepthHandleUnitConverter : public TUnitConverter
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TMeasureManager::CameraSizeProvider *m_cameraSizeProvider;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	CameraZDepthHandleUnitConverter(TMeasureManager::CameraSizeProvider *cameraSizeProvider)
Toshihiro Shimizu 890ddd
		: m_cameraSizeProvider(cameraSizeProvider)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TUnitConverter *clone() const { return new CameraZDepthHandleUnitConverter(m_cameraSizeProvider); }
Toshihiro Shimizu 890ddd
	inline double getCameraSize() const { return (*m_cameraSizeProvider)(); }
Toshihiro Shimizu 890ddd
	double convertTo(double v) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return v * 0.001 * getCameraSize();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	double convertFrom(double v) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return (v / getCameraSize()) * 1000.0;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TMeasureManager::addCameraMeasures(CameraSizeProvider *cameraSizeProvider)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TUnit
Toshihiro Shimizu 890ddd
		u0(L"z"),
Toshihiro Shimizu 890ddd
		u1(L"fld", new ZDepthUnitConverter(cameraSizeProvider)),
Toshihiro Shimizu 890ddd
		u2(L"fld", new CameraZDepthUnitConverter(cameraSizeProvider)),
Toshihiro Shimizu 890ddd
		u3(L"fld", new ZDepthHandleUnitConverter(cameraSizeProvider)),
Toshihiro Shimizu 890ddd
		u4(L"fld", new CameraZDepthHandleUnitConverter(cameraSizeProvider));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TMeasure *zdepth = new TMeasure("zdepth", u0.clone());
Toshihiro Shimizu 890ddd
	TUnit *u = u1.clone();
Toshihiro Shimizu 890ddd
	zdepth->add(u);
Toshihiro Shimizu 890ddd
	zdepth->setCurrentUnit(u);
Toshihiro Shimizu 890ddd
	zdepth->setStandardUnit(u);
Toshihiro Shimizu 890ddd
	TMeasureManager::instance()->add(zdepth);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	zdepth = new TMeasure("zdepth.cam", u0.clone());
Toshihiro Shimizu 890ddd
	u = u2.clone();
Toshihiro Shimizu 890ddd
	zdepth->add(u);
Toshihiro Shimizu 890ddd
	zdepth->setCurrentUnit(u);
Toshihiro Shimizu 890ddd
	zdepth->setStandardUnit(u);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TMeasureManager::instance()->add(zdepth);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	zdepth = new TMeasure("zdepth.handle", u0.clone());
Toshihiro Shimizu 890ddd
	u = u3.clone();
Toshihiro Shimizu 890ddd
	zdepth->add(u);
Toshihiro Shimizu 890ddd
	zdepth->setCurrentUnit(u);
Toshihiro Shimizu 890ddd
	zdepth->setStandardUnit(u);
Toshihiro Shimizu 890ddd
	TMeasureManager::instance()->add(zdepth);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	zdepth = new TMeasure("zdepth.cam.handle", u0.clone());
Toshihiro Shimizu 890ddd
	u = u4.clone();
Toshihiro Shimizu 890ddd
	zdepth->add(u);
Toshihiro Shimizu 890ddd
	zdepth->setCurrentUnit(u);
Toshihiro Shimizu 890ddd
	zdepth->setStandardUnit(u);
Toshihiro Shimizu 890ddd
	TMeasureManager::instance()->add(zdepth);
Toshihiro Shimizu 890ddd
}