// Perso, deprecated
// Checks if the stored mesh equals 'mesh'
//bool SyMorph::has_mesh_changed(MNMesh mesh)
//{
//	return true;
//}

// Perso, deprecated
// Checks if stored params equal current params
//bool SyMorph::has_params_changed()
//{
//	return false;
//}



// Perso, deprecated
//bool SyMorph::invalidate_symorph(MNMesh mesh)
//{
//	this->mesh = mesh;
//	return true;
//}

// Perso, deprecated
//bool same_mnverts(MNVert *a, MNVert *b)
//{
//	if( a->p.x == b->p.x  &&
//		a->p.y == b->p.y &&
//		a->p.z == b->p.z)
//		{
//			return true;
//		}
//	return false;
//}

// Perso, deprecated
//bool SyMorph::same_mnmesh(MNMesh ma, MNMesh mb)
//{
//	int acount = ma.VNum();
//	int bcount = mb.VNum();
//
//	if (acount == bcount)
//	{
//		for (int i = 0; i < acount; i++)
//		{
//			MNVert *va = ma.V(i);
//			MNVert *vb = mb.V(i);
//
//			if( ! same_mnverts(va, vb) )
//			{
//				return false;
//			}
//		}
//		return true;
//	}
//	return false;
//}


/*************************************************************************************************
*   BOOL : should_be_invalidated
	Use  : Checks if (func)pobj->mm == this->mm and if params have changed
	
	Name             : should_be_invalidated
	PolyObject* pobj : object to check against
	float thres      : current threshold value
*	int axis         : current axis value
\************************************************************************************************/
//bool SyMorph::should_be_invalidated(PolyObject* pobj, float thres, int axis)
//{
//	MNMesh mmesh= pobj->GetMesh();
//	if (same_mnmesh(mmesh, mesh)){
//
//		if(1/*this->is_calculated()*/) // Something has been calculated, checks if params are the same.
//		{
//			if (/*thres == this->old_thres && axis == this->old_axis*/ 1)
//			{
//				// All match, don't invalidate
//				return false; 
//			}	
//
//			// Need to invalidate if params are not the same
//			return true;
//		}
//
//		// No need to invalidate if nothing has been calculated yet.
//		return false;
//	}
//	return true;
//}






//	Interface *ip = this->get_ip();
//
//	/* Progress */
//	float p_percent;
//	//LPVOID arg=(0);
//	ip->ProgressStart(_M("Calculating.. Please wait."), TRUE, fn, (LPVOID)0);
//	/* ------------------------------------------------------------- */
//
//
//	if(can_build())
//	{
//
//		
//		//PolyObject* obj = (PolyObject *) _node->GetObjectRef();
//		MNMesh *_mesh = &this->mesh;
//
//
//		// Counts
//		int isolated = 0;
//		int mapped   = 0;
//
//
//		// Reset stats as we build a new map
//		//this->reset_map();
//
//		// -- Outter loop
//		int vcount = _mesh->VNum();
//		
//
//
//		for(int i=0; i<vcount; i++)
//			{
//
//				DebugPrint(_M("."));
//
//				p_percent = 100.0*i/vcount;
//				ip->ProgressUpdate(p_percent);
//
//				/* CANCEL ? */
//				if (ip->GetCancel())
//				{
//                    switch(MessageBox(ip->GetMAXHWnd(), _M("Really Cancel"), _M("Question"), MB_ICONQUESTION | MB_YESNO)) {
//                        case IDYES:
//							this->hard_reset();
//                            return(0);
//                        case IDNO:
//                            ip->SetCancel(FALSE);
//                    }
//                }
//
//
//				// -- Point A (vA)
//				Point3 vA=_mesh->V(i)->p;
//				bool found=false;
//
//				// Inner loop
//				for (int o=0; o<vcount; o++)
//				{
//					if (o==i)continue;
//					if (found)break;
//
//					// Reverse point(o)[get_axis())] to create vB
//					Point3 vB=this->reverse_axis(_mesh->V(o)->p, this->get_axis());
//				
//					// Checks if vA is a valid symmetry of vB
//					if (are_points_symmetrical(vA, vB))
//					{
//						found=true;
//						Point3 pfound((i+1), (1+o), 1);
//						this->AppendToSyMap(&pfound);
//
//						mapped++;
//						//Point2 pfound((i+1),(1+o));
//						//this->map.Append(1, &pfound);
//						
//					}
//				}
//				// Add (i,i) if mirror point hasn't been found
//				if (found!=true)
//				{
//					Point3 pfound((i+1), (i+1), 0);
//					this->AppendToSyMap(&pfound);
//
//					isolated++;
//					//Point2 pfound(i+1,i+1);
//					/*this->map.Append(1, &pfound);*/
//				}
//			}
//
//
//		 // Stop progress bar
//		 ip->ProgressEnd();
//
//
//		// Set params to reflect counts
//		this->setIsolatedCount(isolated);
//		this->setMappedCount(mapped);
//
//		// Updates labels
//		this->update_labels();
//
//		this->makeVertColorSyMap();
//		// Save results to the output file
////		return this->save_to_file();
//		return true;
//	}
//
//	return false;









/*************************************************************************************************
*
	Updates IDC_LBL_PATH to display the value of PB's pb_btn_setpath.
	Called each BeginEditParams and when pb_btn_setpath is set.
*
\************************************************************************************************/
//void SyMorph::set_ui_path()
//{
//	const MCHAR *path = get_path();
//	if (path)
//	{
//		std::wstring wpath = path;
//		if(wpath.length() >= 20) // -- Lenghty string..
//		{
//			wpath = wpath.substr((wpath.length() - 18),wpath.length()); // -- Shrink it to fit IDC_LBL..
//			wpath.insert(0,L"..");
//		}
//		this->labelize(wpath.c_str(), IDC_LBL_PATH);
//		return;
//	}
//
//	this->labelize(_T("Please set a path"), IDC_LBL_PATH);
//	return;
//}


















///*************************************************************************************************
//	Retrieves Path from PBlock
//\************************************************************************************************/
//const MCHAR* SyMorph::get_path()
//{
//	const MCHAR* path;
//	pblock->GetValue(pb_btn_setpath, get_ip()->GetTime(), path, FOREVER);
//	return path;
//}
//
//
//
//
//
//
///*************************************************************************************************
//	Retrieves Path from PBlock
//\************************************************************************************************/
//bool SyMorph::file_is_empty()
//{
//	if(is_path_valid())
//	{
//		if (file_exists())
//		{
//			return true;
//		}
//	}
//	return false;
//}
//
//
//
//
///*************************************************************************************************
//	Do the checks and assigns this->fpath = this->get_path() if looks ok.
//	Returns TRUE|FALSE.
//\************************************************************************************************/
//bool SyMorph::set_path()
//{
//	if(is_path_valid())
//	{
//		this->fpath = MaxSDK::Util::Path(get_path());
//		if (create_file())
//		{
//			set_ui_path();
//			return true;
//		}
//	}
//	return false;
//}
//
//
///*************************************************************************************************
//	Checks if the path contained in PBlock is valid/legal
//\************************************************************************************************/
//bool SyMorph::is_path_valid() // -- Checks if path
//{
//	const MCHAR *path = get_path();
//	if (path)
//	{
//		BFSDK::Utils::PathHelper p_path(path);
//		//MaxSDK::Util::Path p_path(path);
//		
//		return p_path.is_valid();
//		//return p_path.IsLegal();
//	}
//	return false;
//}
//
//
//
///*************************************************************************************************
//	Checks if there is a file pointed by PBlock's path
//\************************************************************************************************/
//bool SyMorph::file_exists()
//{
//	if(is_path_valid())
//	{
//		const MCHAR *path = get_path();
//		MaxSDK::Util::Path p_path(path);
//		return p_path.Exists();
//	}
//	return false;
//}
//
///*************************************************************************************************
//	Creates the file pointed by PBlock's path
//\************************************************************************************************/
//bool SyMorph::create_file()
//{
//	if(is_path_valid()/* && !file_exists()*/)
//	{
//		//MaxSDK::Util::TextFile::ReaderWriter rw;
//		FILE* file = _tfopen(this->fpath.GetCStr(), _T("w+, ccs=UTF-8"));
//		if(file)
//		{
//			fclose(file);
//			return true;
//		}
//	}
//	return false;
//}
//
///*************************************************************************************************
//	Saves data to PBlock's path // Used internaly 
//\************************************************************************************************/
//bool SyMorph::save_to_file()
//{
//	FILE* file = _tfopen(this->fpath.GetCStr(), _T("wt, ccs=UTF-8"));
//	if(file)
//	{
//		int vcount = this->map.Count();
//		if (vcount)
//		{
//			
//			//_ftprintf(file, _T("%s"), _T("----------SyMorph-Map-Start----------\n")); // -- Header
//			for(int i=0; i<vcount; i++)
//			{
//				Point2 p = this->map[i];
//				//_ftprintf(file, _T("%i:%i\n"), (int)p.x, (int)p.y);
//				_ftprintf(file, _T("%i %i\n"), (int)p.x, (int)p.y);
//			}
//			//_ftprintf(file, _T("%s"), _T("-----------SyMorph-Map-End-----------")); // -- Footer
//
//		}
//		fclose(file);
//
//		this->sync_map_checksum();
//		return true;
//	}
//	return false;
//}
//
///*************************************************************************************************
//	Loads file data
//\************************************************************************************************/
//bool SyMorph::load_from_file()
//{
//	return false;
//}

/*************************************************************************************************
	Assigns file's checksum to PBLock->pb_map_checksum
\************************************************************************************************/
//void SyMorph::sync_map_checksum()
//{
//	TSTR mapcheck = this->make_mapfile_checksum();
//	MCHAR* m = mapcheck.dataForWrite();
//
//	this->GetParamBlock(0)->SetValue(pb_map_checksum, this->get_ip()->GetTime(), m);
//}
//
//
//
///*************************************************************************************************
//	Compares PBlock's checksum and file's checksum
//\************************************************************************************************/
//bool SyMorph::compare_checksums()
//{
//	IParamBlock2 *ipb = this->GetParamBlock(0);
//	MSTR local = ipb->GetStr(pb_map_checksum);
//	if(!local.isNull())
//	{
//
//		MSTR path = this->get_path();
//		if(!path.isNull())
//		{
//			MSTR file_chk = this->make_mapfile_checksum();
//
//			if(!file_chk.isNull())
//			{
//				if (file_chk == local)
//				{
//					return true;
//				}
//			}
//		}
//	}
//	return false;
//}




/*************************************************************************************************
	Loads map pointed by get_path() if exists and if the checksum matches pblock
\************************************************************************************************/
//typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
//bool SyMorph::load_map_tab()
//{
//	TSTR path = get_path();
//	std::string p = path.ToCStr().data();
//
//	if(! path.isNull())
//	{
//		if(this->compare_checksums())
//		{
//			std::ifstream file(p);
//			boost::char_separator<char> sep(":");
//		
//			std::string line;
//			while(std::getline(file, line))
//			{		
//				tokenizer tokens(line, sep);
//				for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
//				{
//					std::string val = *tok_iter;
//					TSTR wval = TSTR::FromACP(val.c_str());
//					wval.Append(_M("\n"));
//					DebugPrint(wval);
//				}
//			}
//			return true;
//		}
//		else // checksums mismatch
//		{
//
//			this->reset_map();
//			this->reset_stats();
//
//		}
//	}
//	return false;
//}


















/*************************************************************************************************
	ProgressBAR FN
\************************************************************************************************/
//DWORD WINAPI fn(LPVOID arg)
//{
//        int i, percent;
//        Interface *ip = theUtility.ip;
//        for (i = 0; i < 1000; i++) {
//                percent = i/10;
//                ip->ProgressUpdate(percent);
//                if (ip->GetCancel()) {
//                        switch(MessageBox(ip->GetMAXHWnd(), _M("Really Cancel"), _M("Question"), MB_ICONQUESTION | MB_YESNO)) {
//                                case IDYES:
//                                        return(0);
//                                        case IDNO:
//                                        ip->SetCancel(FALSE);
//                        }
//                }
//        }
//        return(0);
//}





// Computes a MD5 checksum of the mapfile
//TSTR SyMorph::make_mapfile_checksum()
//{
//	std::ifstream istr(this->get_path(), std::ios::binary);
//	if (istr)
//	{
//		Poco::MD5Engine md5;
//		Poco::DigestOutputStream dos(md5);	
//		Poco::StreamCopier::copyStream(istr, dos);
//		dos.close();
//
//		std::string checksum = Poco::DigestEngine::digestToHex(md5.digest());
//		TSTR tscheck = TSTR::FromACP(checksum.c_str());
//		
//		return tscheck;
//	}
//	return _T("");
//}



// PBLOCK MAP !
// -----------------------------------------------


//
//TP3 SyMorph::GetSyMap()
//{
//	IParamBlock2 *pblock = this->GetParamBlock(0);
//	TP3 map;
//
//	int elem_count = pblock->Count(pb_mapping);
//	for(int i=0; i<elem_count; i++)
//	{
//		Point3 *p = &(pblock->GetPoint3(pb_mapping, get_ip()->GetTime(), i));
//		map.Append(1, p);
//	}
//	return map;
//}// -- Returns pblock's symap
//
//void SyMorph::SetSyMap(TP3 m)
//{
//}// -- Sets pblock's symap = m
//








