Skip to content
OE_stitchs.h 3.97 KiB
Newer Older
3dsman's avatar
3dsman committed
/*
 * Copyright (c) 2015 Tricoire Sebastien 3dsman@free.fr
 *
 * This software is provided 'as-is', without any express or implied
 * warranty.  In no event will the authors be held liable for any damages
 * arising from the use of this software.
 *
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute it
 * freely, subject to the following restrictions:
 *
 * 1. The origin of this software must not be misrepresented; you must not
 * claim that you wrote the original software. If you use this software
 * in a product, an acknowledgment in the product documentation would be
 * appreciated but is not required.
 * 2. Altered source versions must be plainly marked as such, and must not be
 * misrepresented as being the original software.
 * 3. This notice may not be removed or altered from any source distribution.
 *
 */

raoul's avatar
raoul committed
#pragma once
3dsman's avatar
3dsman committed

3dsman's avatar
3dsman committed
#include "OE_utils.h"
3dsman's avatar
3dsman committed
#include <stdint.h>
#include <vector>
raoul's avatar
raoul committed
#include "OE_fstream.h"
3dsman's avatar
3dsman committed

raoul's avatar
raoul committed
namespace Pakal { class Archive; }

class OE_stitchs : public OE_base
3dsman's avatar
3dsman committed
{
raoul's avatar
raoul committed
	public:
		/** Default constructor */
		OE_stitchs();
		/** Default destructor */
		virtual ~OE_stitchs();
		//virtual bool getNeedRefresh();
		//virtual bool setNeedRefresh(bool value);
3dsman's avatar
3dsman committed

raoul's avatar
raoul committed
		virtual void persist(Pakal::Archive* archive);
raoul's avatar
raoul committed

raoul's avatar
raoul committed
		/** \brief to get a point in the stitch. */
		bool getPoint(uint16_t nb, float* x, float* y);
		bool getPoint(uint16_t nb, vector_2d* pt);

		/** \brief return a copy of the array of points*/
raoul's avatar
raoul committed
		const std::vector<vector_2d>& getPoints();
raoul's avatar
raoul committed

		/** \brief return the number of points in the stitch (control points, without handles) */
		int getNpts();

		/** \brief to get the thread. */
		OE_thread* getThread();

		/** \brief to set a point in the stitch. */
		bool setPoint(uint16_t nb, float x, float y);

		/** \brief to set the thread. */
		bool setThread(OE_thread* thread);

		/** \brief to add a point at the end of the stitch. */
		bool addPoint( float x, float y);
3dsman's avatar
3dsman committed
		bool addPoint( vector_2d pt);
raoul's avatar
raoul committed

		/** \brief set the max len of a segment */
raoul's avatar
raoul committed
		float getMaxLen();

		/** \brief return an array of point splited to respect the maxLen distance */
		std::vector<vector_2d> stitchMaxLen(std::vector<vector_2d> ptsArray, float maxlen);
		/** \brief process stitches after calculation */
		virtual void stitchPostProcess(std::vector<vector_2d> ptsArray);

		/** \brief return an array of warped stitchs from positions and normals arrays of same size and a pattern
		 *  \brief offset is used to offset the pattern along normal
		 */
		std::vector<vector_2d> warpStitch(std::vector<vector_2d> mainPts, std::vector<vector_2d> normalPts, bool normals,
raoul's avatar
raoul committed
		                                  OE_pattern* pattern, unsigned patternSteps=1,
		                                  float xOffset=0, float yOffset=0);
3dsman's avatar
3dsman committed
		/** \brief calculate the curve bounding box
		 * \param xMin,yMin,xMax,yMax -> pointers to the bouding box variables to set
raoul's avatar
raoul committed
		 */
		virtual BoundingBox getBound();

		/** \brief check if the stitch is valid. */
		virtual bool check();

		virtual void refresh(float dpi, bool force = false) = 0;
raoul's avatar
raoul committed
		virtual void refreshDependency() {}

		/** \brief move the stitch
		 */
		virtual void move(vector_2d /*offset*/) {}
		virtual void scale(vector_2d /*ratio*/, vector_2d /*pos*/) {}
raoul's avatar
raoul committed

3dsman's avatar
3dsman committed

raoul's avatar
raoul committed
	protected:
3dsman's avatar
3dsman committed
		/** \brief Tight bounding box of the shape [minx,miny,maxx,maxy]. */
raoul's avatar
raoul committed
		//float bounds[4];

		/** \brief the thread associate to this stitch */
raoul's avatar
raoul committed
		OE_thread* thread;

		/** \brief the array of stitch points */
		std::vector<vector_2d> pts;

raoul's avatar
raoul committed

3dsman's avatar
3dsman committed
		/** \brief check if a point is in a given bounding box
		 * \param pt -> the point
		 * \param bounds -> an array representing the bounding box
		 * \return true if the point is inside the bounding box
		 */
raoul's avatar
raoul committed
		//static bool ptInBounds( vector_2d pt, float* bounds);
3dsman's avatar
3dsman committed
};