//------------------------------------------------------------------------
	MaterialPtr MaterialUtil::generateMaterial(const MtlPtr& _mtl, const MatGenParams& _matGenParams)
	{
		MaterialPtr material;
		Mtl::MaterialHandles::iterator it = _mtl->mMaterialHandles.find(_matGenParams);
		if(it != _mtl->mMaterialHandles.end())
		{
			// Material was generated already, just return it
			// (Materials can be shared.)
			ResourceHandle handle = it->second;
			material = MaterialManager::getSingleton().getByHandle(handle);
		}
		else
		{
			// Generate a new material
			String materialName = s_MaterialNameGenerator.generate();
			material = MaterialManager::getSingleton().create(materialName, StringUtil::BLANK);
			
			// We need a material generator.
			MaterialGenerator* generator = MaterialGeneratorRegistration::getSingleton().getGenerator();

			// Initalise the material with the specified params.
			generator->_updateMaterial(material, _mtl, _matGenParams);

			// Store the smart pointer to the mtl and the material generation params
			// in the material's "user any" member.
			if(!material->getNumTechniques())
			{
				MaterialManager::getSingleton().remove( (ResourcePtr) material);
				return MaterialPtr();
			}
			Technique* technique = material->getTechnique(0);
			UserObjectBindings& uob = technique->getUserObjectBindings();
			uob.setUserAny( USER_MTL, (Any) _mtl );
			uob.setUserAny( USER_MAT_GEN_PARAMS, (Any) _matGenParams );

			// Store the handle to the new material in the mtl.
			ResourceHandle handle = material->getHandle();
			_mtl->mMaterialHandles.insert(std::make_pair(_matGenParams, handle));
		}
		return material;
	}
Exemple #2
0
Button* Button::create(Container* container)
{
	WidgetFactory* wf = UiModule::instance()->getWidgetFactory();
	Button* btn = wf->createButton(sButtonNameGenerator.generate(), container);
	return btn;
}
namespace GothOgre
{
	//------------------------------------------------------------------------
	static const String USER_MTL = "Mtl";
	static const String USER_MAT_GEN_PARAMS = "MatGenParams";
	static NameGenerator s_MaterialNameGenerator("Auto");
	//--------------------------------------------------------------------------
	// Without the following declaration we cannot pack MtlPtr to Ogre::Any.
	template<class _Elem, class _Traits> 
	inline std::basic_ostream<_Elem, _Traits>& operator<<(
		std::basic_ostream<_Elem, _Traits>& _ostrm, const MtlPtr& _val)
	{
		return _ostrm;
	}

	template<class _Elem, class _Traits> 
	inline std::basic_ostream<_Elem, _Traits>& operator<<(
		std::basic_ostream<_Elem, _Traits>& _ostrm, const MatGenParams& _val)
	{
		return _ostrm;
	}
	//------------------------------------------------------------------------
	MaterialPtr MaterialUtil::generateMaterial(const MtlPtr& _mtl, const MatGenParams& _matGenParams)
	{
		MaterialPtr material;
		Mtl::MaterialHandles::iterator it = _mtl->mMaterialHandles.find(_matGenParams);
		if(it != _mtl->mMaterialHandles.end())
		{
			// Material was generated already, just return it
			// (Materials can be shared.)
			ResourceHandle handle = it->second;
			material = MaterialManager::getSingleton().getByHandle(handle);
		}
		else
		{
			// Generate a new material
			String materialName = s_MaterialNameGenerator.generate();
			material = MaterialManager::getSingleton().create(materialName, StringUtil::BLANK);
			
			// We need a material generator.
			MaterialGenerator* generator = MaterialGeneratorRegistration::getSingleton().getGenerator();

			// Initalise the material with the specified params.
			generator->_updateMaterial(material, _mtl, _matGenParams);

			// Store the smart pointer to the mtl and the material generation params
			// in the material's "user any" member.
			if(!material->getNumTechniques())
			{
				MaterialManager::getSingleton().remove( (ResourcePtr) material);
				return MaterialPtr();
			}
			Technique* technique = material->getTechnique(0);
			UserObjectBindings& uob = technique->getUserObjectBindings();
			uob.setUserAny( USER_MTL, (Any) _mtl );
			uob.setUserAny( USER_MAT_GEN_PARAMS, (Any) _matGenParams );

			// Store the handle to the new material in the mtl.
			ResourceHandle handle = material->getHandle();
			_mtl->mMaterialHandles.insert(std::make_pair(_matGenParams, handle));
		}
		return material;
	}
	//------------------------------------------------------------------------
	void MaterialUtil::updateAllMaterials(const MtlPtr& _mtl)
	{
		// We need a material generator.
		MaterialGenerator* generator = MaterialGeneratorRegistration::getSingleton().getGenerator();

		// Update all materials generated based on the specified mtl.
		for(Mtl::MaterialHandles::iterator it = _mtl->mMaterialHandles.begin();
			it != _mtl->mMaterialHandles.end(); ++it)
		{
			const MatGenParams& matGenParams = it->first;
			ResourceHandle handle = it->second;
			MaterialPtr material = MaterialManager::getSingleton().getByHandle(handle);
			generator->_updateMaterial(material, _mtl, matGenParams);
		}
	}
	//------------------------------------------------------------------------
	MtlPtr MaterialUtil::getMtl(const MaterialPtr& _material)
	{
		if(!_material->getNumTechniques())
			return MtlPtr();
		
		Technique* technique = _material->getTechnique(0);
		UserObjectBindings& uob = technique->getUserObjectBindings();
		Any mtlAny = uob.getUserAny( USER_MTL );
		
		if(mtlAny.isEmpty())
			return MtlPtr();

		MtlPtr mtl = *any_cast<MtlPtr>(&mtlAny);
		return mtl;		
	}
	//------------------------------------------------------------------------
	MtlPtr MaterialUtil::getMtl(const MaterialPtr& _material, MatGenParams& _rMatGenParams)
	{
		if(!_material->getNumTechniques())
			return MtlPtr();
		
		Technique* technique = _material->getTechnique(0);
		UserObjectBindings& uob = technique->getUserObjectBindings();
		Any mtlAny = uob.getUserAny( USER_MTL );
		Any matGenParamsAny = uob.getUserAny( USER_MAT_GEN_PARAMS );
		
		if(mtlAny.isEmpty() || matGenParamsAny.isEmpty())
			return MtlPtr();

		MtlPtr mtl = *any_cast<MtlPtr>(&mtlAny);
		_rMatGenParams = *any_cast<MatGenParams>(&matGenParamsAny);
		return mtl;	
	}
	//------------------------------------------------------------------------
	MtlPtr MaterialUtil::getMtl(const MaterialPtr& _material, MatGenParams* _rMatGenParams)
	{
		return getMtl(_material, *_rMatGenParams);
	}
	//------------------------------------------------------------------------
	MatGenParams MaterialUtil::getMatGenParams(const MaterialPtr& _material)
	{
		if(!_material->getNumTechniques())
			return MatGenParams();
		
		Technique* technique = _material->getTechnique(0);
		UserObjectBindings& uob = technique->getUserObjectBindings();
		Any matGenParamsAny = uob.getUserAny( USER_MAT_GEN_PARAMS );
		
		if(matGenParamsAny.isEmpty())
			return MatGenParams();

		return *any_cast<MatGenParams>(&matGenParamsAny);
	}

} // namespace GothOgre
Exemple #4
0
Label* Label::create(Container* container)
{
	WidgetFactory* wf = UiModule::instance()->getWidgetFactory();
	Label* label = wf->createLabel(sLabelNameGenerator.generate(), container);
	return label;
}
Exemple #5
0
Container* Container::create(Layout layout, Container* container)
{
    WidgetFactory* wf = UiModule::instance()->getWidgetFactory();
    return wf->createContainer(sContainerNameGenerator.generate(), container, layout);
}
Exemple #6
0
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

#include "datad.h"

NameGenerator name_generator;
std::string AsyncRequestClient::id = name_generator.get_unique_id();

std::string AsyncRequestClient::get_id(){
	return id;
}

AsyncRequestClient::AsyncRequestClient(std::string server){
	this -> server = server;
}

void AsyncRequestClient::connect(){
}

void AsyncRequestClient::disconnect(){
}
void findSegmentImpl(const Mat& img, const Rect& roi, vector< Point_<T> >& outQuad){

	//quad finding modes:
	//There is a tradeoff with using intersections.
	//It seems to work better on messy segments, however,
	//on segments with multiple min energy lines we are more likely
	//to choose the wrong line than with the contour method.
	#define QUAD_FIND_INTERSECTION 0
	#define QUAD_FIND_CONTOURS 1
	
	#define QUAD_FIND_MODE QUAD_FIND_INTERSECTION
	
	Mat imgThresh, temp_img, temp_img2;
	
	//A binary image gradient is applied here.
	//You can use findLines without it, but it
	//generally leads to better performance.
	//However, it may lead to a loss in percision.
	//i.e. you're more likely to find the right line, but the coords will be slightly off.
	int blurSize = 40;
	blur(img, temp_img, Size(blurSize, blurSize));
	imgThresh = (img - temp_img) > 0;
	//White out the middle of the segment to prevent it from interfering.
	Rect contractedRoi = resizeRect(roi, .7);
	imgThresh(contractedRoi) = Scalar::all(255);

	Point_<T> A1, B1, A2, B2, A3, B3, A4, B4;
	findLines(imgThresh, A1, B1, roi, false, true);
	findLines(imgThresh, A2, B2, roi, false, false);
	findLines(imgThresh, A3, B3, roi, true, true);
	findLines(imgThresh, A4, B4, roi, true, false);

	#if QUAD_FIND_MODE == QUAD_FIND_INTERSECTION
		vector< Point_<T> > quad;
		quad.push_back(findIntersection(A1, B1, A2, B2));
		quad.push_back(findIntersection(A2, B2, A3, B3));
		quad.push_back(findIntersection(A3, B3, A4, B4));
		quad.push_back(findIntersection(A4, B4, A1, B1));
		outQuad = quad;
	#elif QUAD_FIND_MODE == QUAD_FIND_CONTOURS
		line( imgThresh, A1, B1, Scalar::all(0), 1, 4);
		line( imgThresh, A2, B2, Scalar::all(0), 1, 4);
		line( imgThresh, A3, B3, Scalar::all(0), 1, 4);
		line( imgThresh, A4, B4, Scalar::all(0), 1, 4);
		Mat imgThresh2;
		imgThresh.copyTo(imgThresh2);
		vector< Point > quad = findMaxQuad(imgThresh2, 0);
		//This works poorly on large rectangles
		//#define EXPANSION_PERCENTAGE .01
		//quad = expandCorners(quad, EXPANSION_PERCENTAGE);
		quad = orderCorners(quad);
		convertQuad(quad, outQuad);
	#endif
	
	//refineCorners(img, quad);
	#ifdef OUTPUT_DEBUG_IMAGES

		Mat dbg_out, dbg_out2;
		imgThresh.copyTo(dbg_out);

		vector< Point > roundQuad;

		roundQuad.push_back(quad[0]);
		roundQuad.push_back(quad[1]);
		roundQuad.push_back(quad[2]);
		roundQuad.push_back(quad[3]);

		const Point* p = &roundQuad[0];
		int n = (int) quad.size();
		polylines(dbg_out, &p, &n, 1, true, Scalar::all(100), 1, CV_AA);
		//debugShow(dbg_out);

		string segfilename = alignmentNamer.get_unique_name("alignment_debug_");
		segfilename.append(".jpg");
		imwrite(segfilename, dbg_out);
	#endif
}
Exemple #8
0
Slider* Slider::create(Container* container)
{
	WidgetFactory* wf = UiModule::instance()->getWidgetFactory();
	Slider* slider = wf->createSlider(sSliderNameGenerator.generate(), container);
	return slider;
}