Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// PatternPosition.h: interface for the CPatternPosition class.
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//////////////////////////////////////////////////////////////////////
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#if !defined(                                                                  \
Shinya Kitaoka 120a6e
    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
#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
Shinya Kitaoka 120a6e
class CPatternPosition {
Shinya Kitaoka 120a6e
  bool isInSet(const int nbSet, const int *set, const int val);
Shinya Kitaoka 120a6e
  void makeRandomPositions(const int nbPat, const int nbPixel, const int lX,
Shinya Kitaoka 120a6e
                           const int lY, const UCHAR *sel);
Shinya Kitaoka 120a6e
  void makeDDPositions(const int lX, const int lY, UCHAR *sel,
Shinya Kitaoka 120a6e
                       const double minD, const double maxD);
Shinya Kitaoka 120a6e
  void getPosAroundThis(const int lX, const int lY, const UCHAR *lSel,
Shinya Kitaoka 120a6e
                        const int xx, const int yy, int &xPos, int &yPos);
Shinya Kitaoka 120a6e
  bool findEmptyPos(const int lX, const int lY, const UCHAR *lSel, int &xPos,
Shinya Kitaoka 120a6e
                    int &yPos, SRECT &bb);
Shinya Kitaoka 120a6e
  void eraseCurrentArea(const int lX, const int lY, UCHAR *lSel,
Shinya Kitaoka 120a6e
                        std::vector<spoint> &ddc, const int xx, const int yy);</spoint>
Shinya Kitaoka 120a6e
  void sel0255To01(const int lX, const int lY, UCHAR *sel, SRECT &bb);
Shinya Kitaoka 120a6e
  void prepareCircle(std::vector<spoint> &v, const double r);</spoint>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  std::vector<spoint> m_pos;</spoint>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  CPatternPosition() : m_pos(0){};
Shinya Kitaoka 120a6e
  virtual ~CPatternPosition();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  template <class p=""></class>
Shinya Kitaoka 120a6e
  CPatternPosition(CSTColSelPic

&p, const int nbPixel, const double dens,

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

&pic) {

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