Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// PatternPosition.h: interface for the CPatternPosition class.
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//////////////////////////////////////////////////////////////////////
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if !defined(AFX_PATTERNPOSITION_H__9FB82504_34F2_11D6_B9E8_0040F674BE6A__INCLUDED_)
Toshihiro Shimizu 890ddd
#define AFX_PATTERNPOSITION_H__9FB82504_34F2_11D6_B9E8_0040F674BE6A__INCLUDED_
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if _MSC_VER > 1000
Toshihiro Shimizu 890ddd
#pragma once
Toshihiro Shimizu 890ddd
#endif // _MSC_VER > 1000
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <vector></vector>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <stdlib.h></stdlib.h>
Toshihiro Shimizu 890ddd
#include "STColSelPic.h"
Toshihiro Shimizu 890ddd
#include "SError.h"
Toshihiro Shimizu 890ddd
#include "SDef.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class CPatternPosition
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool isInSet(const int nbSet, const int *set, const int val);
Toshihiro Shimizu 890ddd
	void makeRandomPositions(const int nbPat, const int nbPixel,
Toshihiro Shimizu 890ddd
							 const int lX, const int lY, const UCHAR *sel);
Toshihiro Shimizu 890ddd
	void makeDDPositions(const int lX, const int lY, UCHAR *sel,
Toshihiro Shimizu 890ddd
						 const double minD, const double maxD);
Toshihiro Shimizu 890ddd
	void getPosAroundThis(const int lX, const int lY, const UCHAR *lSel,
Toshihiro Shimizu 890ddd
						  const int xx, const int yy,
Toshihiro Shimizu 890ddd
						  int &xPos, int &yPos);
Toshihiro Shimizu 890ddd
	bool findEmptyPos(const int lX, const int lY, const UCHAR *lSel,
Toshihiro Shimizu 890ddd
					  int &xPos, int &yPos, SRECT &bb);
Toshihiro Shimizu 890ddd
	void eraseCurrentArea(const int lX, const int lY, UCHAR *lSel,
Shinya Kitaoka 3bfa54
						  std::vector<spoint> &ddc, const int xx, const int yy);</spoint>
Toshihiro Shimizu 890ddd
	void sel0255To01(const int lX, const int lY, UCHAR *sel, SRECT &bb);
Shinya Kitaoka 3bfa54
	void prepareCircle(std::vector<spoint> &v, const double r);</spoint>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 3bfa54
	std::vector<spoint> m_pos;</spoint>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	CPatternPosition() : m_pos(0){};
Toshihiro Shimizu 890ddd
	virtual ~CPatternPosition();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	template <class p=""></class>
Toshihiro Shimizu 890ddd
	CPatternPosition(CSTColSelPic

&p, const int nbPixel, const double dens,

Toshihiro Shimizu 890ddd
					 const double minD, const double maxD)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		try {
Toshihiro Shimizu 890ddd
			m_pos.clear();
Toshihiro Shimizu 890ddd
			if (dens > 0.00001) {
Toshihiro Shimizu 890ddd
				// Random position
Toshihiro Shimizu 890ddd
				int nbPat = I_ROUND(((double)nbPixel * dens));
Toshihiro Shimizu 890ddd
				//			nbPat= nbPat>(int)(0.9*nbPixel) ?  (int)(0.9*nbPixel) : nbPat;
Toshihiro Shimizu 890ddd
				nbPat = nbPat > nbPixel ? nbPixel : nbPat;
Toshihiro Shimizu 890ddd
				if (nbPat > 0)
Shinya Kitaoka 6a4e01
					makeRandomPositions(nbPat, nbPixel, p.m_lX, p.m_lY, p.m_sel.get());
Toshihiro Shimizu 890ddd
			} else {
Toshihiro Shimizu 890ddd
				// Distance-driven position
Shinya Kitaoka 6a4e01
				makeDDPositions(p.m_lX, p.m_lY, p.m_sel.get(), minD, maxD);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		} catch (SMemAllocError) {
Toshihiro Shimizu 890ddd
			throw;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	template <class p=""></class>
Toshihiro Shimizu 890ddd
	void drawTest(CSTColSelPic

&pic)

Toshihiro Shimizu 890ddd
	{
Shinya Kitaoka 3bfa54
		for (std::vector<spoint>::iterator pv = m_pos.begin();</spoint>
Toshihiro Shimizu 890ddd
			 pv != m_pos.end();
Toshihiro Shimizu 890ddd
			 pv++) {
Toshihiro Shimizu 890ddd
			int xx = pv->x;
Toshihiro Shimizu 890ddd
			int yy = pv->y;
Toshihiro Shimizu 890ddd
			for (int y = yy - 1; y <= (yy + 1); y++)
Toshihiro Shimizu 890ddd
				for (int x = xx - 1; x <= (xx + 1); x++)
Toshihiro Shimizu 890ddd
					if (x >= 0 && y >= 0 && x < pic.m_lX && y < pic.m_lY) {
Toshihiro Shimizu 890ddd
						UC_PIXEL *pp = pic.m_pic + y * pic.m_lX + x;
Toshihiro Shimizu 890ddd
						pp->r = 0;
Toshihiro Shimizu 890ddd
						pp->g = 0;
Toshihiro Shimizu 890ddd
						pp->b = 255;
Toshihiro Shimizu 890ddd
						pp->m = 255;
Toshihiro Shimizu 890ddd
					}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif // !defined(AFX_PATTERNPOSITION_H__9FB82504_34F2_11D6_B9E8_0040F674BE6A__INCLUDED_)