Minimal Tajima DST (.dst) reader for openFrameworks
README
ofxDST (openFrameworks addon)
Tajima DST(.dst)を openFrameworks で読むための最小アドオンです。
内部で dst-cpp を submodule として使用しています。
動作環境
- openFrameworks 0.11.x / 0.12.x
- macOS / Windows / Linux
- C++17
できること
.dstを読み込む(512ヘッダ + 3バイトレコード列)- レコードをデコードして 絶対座標の点列を返す
- ヘッダ情報(デザイン名、ステッチ数、カラーチェンジ数など)を取得する
- 外形(bounds)を計算する
draw()で簡易プレビュー(stitchのみ線を引く)
できないこと(重要)
- サテン/フィル等の"オブジェクト情報"の復元
- 密度/アンダーレイ/補正などの上位情報の復元
- TRIMの確定(DSTでは曖昧・機械依存)
インストール
# git clone する場合は --recursive を付ける
git clone --recursive https://github.com/daitomanabe/ofxDST.git
既にclone済みの場合は submodule を初期化
git submodule update --init --recursive1.
ofxDST フォルダを openFrameworks/addons/ofxDST にコピー 2. example-ofxDST を openFrameworks の Project Generator で生成 - 既に
addons.makeにofxDSTが書いてあるので、アドオン追加は不要なはずです
サンプルDSTファイルは
example-ofxDST/bin/data/ に入っています。ディレクトリ構成
ofxDST/
├── src/
│ ├── ofxDST.h # openFrameworks用ラッパー
│ └── ofxDST.cpp
├── libs/
│ └── dst-cpp/ # submodule (https://github.com/daitomanabe/dst-cpp)
│ ├── include/dst/dst.hpp
│ └── src/dst.cpp
├── example-ofxDST/
│ └── bin/data/sample.dst
├── addon_config.mk
└── README.md使い方(コード)
ofxDST::Reader dst;
dst.load("sample.dst");
// 外形を取得(DST単位、通常0.1mm)
auto bounds = dst.getBounds();
// 描画
dst.draw(100, 100, 1.0f, true);API リファレンス
ofxDST::Reader
| メソッド | 説明 |
|---|---|
bool load(const std::string& path) | DSTファイルを読み込む。成功で true |
void clear() | 読み込みデータをクリア |
const std::unordered_map<std::string, std::string>& getHeaderTags() | ヘッダ情報を取得(LA, ST, CO 等) |
const std::vector<Record>& getRecords() | 相対移動レコードを取得 |
const std::vector<Point>& getPoints() | 絶対座標の点列を取得 |
const ofRectangle& getBounds() | 外形を取得(DST単位) |
void draw(float x, float y, float scale, bool flipY) | 簡易描画 |
draw() の引数
| 引数 | 型 | 説明 |
|---|---|---|
x | float | スクリーン上のX座標(ピクセル) |
y | float | スクリーン上のY座標(ピクセル) |
scale | float | DST単位あたりのピクセル数(デフォルト: 1.0) |
flipY | bool | Y軸を反転するか(デフォルト: true) |
型定義(dst-cpp からの re-export)
using ofxDST::Command = dst::Command; // Stitch, Jump, Stop, Sequin, End
using ofxDST::Point = dst::Point; // x, y, cmd
using ofxDST::Record = dst::Record; // dx, dy, cmd
using ofxDST::Header = dst::Header; // tags (unordered_map)ヘッダタグ(主要なもの)
| タグ | 説明 |
|---|---|
LA | デザイン名(Label) |
ST | ステッチ数 |
CO | カラーチェンジ数 |
+X, -X, +Y, -Y | 各方向への最大移動量 |
ofxDST::Command(コマンド種別)
| 値 | 説明 |
|---|---|
Stitch | 通常のステッチ(糸を縫う) |
Jump | ジャンプ移動(糸を縫わない) |
Stop | 停止(糸色変更のタイミング) |
Sequin | スパンコール |
End | データ終端 |
座標の向き
DSTのY軸は「上が+」として扱うことが多い一方、openFrameworksは画面座標が「下が+」です。
draw(..., flipY=true) でY方向を反転して表示します。ライセンス
MIT License
ofxAddons