STL ファイルから SVG スライスを作成します。SVG ファイルは多数の行で構成されています。短いバージョンは、JavaFX の組み込み機能を使用して SVG の塗りつぶしパターンを作成できないというものです。その理由は、SVG が正しく作成されていないことに関係していました。これは、コードが移動してから行を実行し、次に移動してから行を実行するためです。塗りつぶし機能を使用するには、1 回の移動と複数の行が必要だと思います。正確な問題を思い出すには、あまりにも昔のことです。
これは、塗りつぶしパターン、ハニカム塗りつぶしパターンをファイルに保存する問題を解決するために現在行っていることです。これはもちろんメモリに保存できますが、テスト用です。次に、中空スライスを 2 番目のファイルに保存します。レイヤー/スライス表示の内側にあるハニカムの部分と残りの部分だけが削除されるように、2 つを組み合わせる必要があります。ハニカムは白く、スライスも白くする必要があります。スライスにコピーするときに、ハニカムを白くする計画でした。
2つの方法を試しました。
最初に試した方法は、塗りつぶしパターンからレイヤー/スライスにピクセルをコピーすることでした。レイヤーの線がどこにあるかを見つけようとし、次に内側と外側がどこにあるかを把握しようとしました。私は失敗しました。コードはこの質問の最後に添付されます。
私が試した 2 番目の方法は、blendMode を使用することでしたが、どのモードも必要な機能を実行していないようです。
ハニカムとレイヤーを異なる色で保存しようとした最初のメソッドコード、それらを重ねて保存してからハニカムを削除しようとしました。ここで、何が内側で何が外側かを把握しようとしていることがわかりますが、うまくいきませんでした
package javaapplication3;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.image.PixelReader;
import javafx.scene.image.PixelWriter;
import javafx.scene.image.WritableImage;
import javafx.scene.paint.Color;
import javax.imageio.ImageIO;
public class JavaApplication3 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
File file = new File("C:\\Temp\\Mandibular\\MandibularsolidNOreferencepoints.gizmofill0.gizmoslice.png");
BufferedImage bufImage = ImageIO.read(file);
WritableImage writableImage = SwingFXUtils.toFXImage(bufImage, null);
PixelReader pixelReader = writableImage.getPixelReader();
int width = (int) writableImage.getWidth();
int height = (int) writableImage.getHeight();
WritableImage dest = new WritableImage(width, height);
PixelWriter writer = dest.getPixelWriter();
boolean isOnLine = false;
boolean previousIsOnLine = false;
boolean isInside = false;
for (int x = 0; x < width; x++) {
for (int y = 00; y < height; y++) {
// reading a pixel from src image,
// then writing a pixel to dest image
Color color = pixelReader.getColor(x, y);
double red = color.getRed();
double green = color.getGreen();
double blue = color.getBlue();
if (red == 0 && green == 1 && blue == 0) {
//isInside = !isInside;
isOnLine = true;
} else {
previousIsOnLine = isOnLine;
isOnLine = false;
}
if (previousIsOnLine) {
isInside = !isInside;
}
/*if (isOnLine && red == 1 && green == 0 && blue == 0) {
isInside = true;
isOnLine = false;
}*/
if (isOnLine || isInside) {
writer.setColor(x, y, color);
}
/*if (isOnLine || isInside && (red > 0 && green == 0 && blue == 0)) {
writer.setColor(x, y, Color.WHITE);
}*/
}
}
File outputFile = new File("C:\\Temp\\Mandibular\\test.png");
ImageIO.write(SwingFXUtils.fromFXImage(dest, null), "png", outputFile);
} catch (IOException ex) {
Logger.getLogger(JavaApplication3.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
ブレンドを使用する2番目の方法 は、さまざまなblendModesを試し、最後のlayerView.setBlendMode(BlendMode.SRC_ATOP);で終了しました。それは明らかに私が必要とすることをしません。それぞれをテストして、何が機能するかを確認しました
package javafxapplication15;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.embed.swing.SwingFXUtils;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.SnapshotParameters;
import javafx.scene.control.Button;
import javafx.scene.effect.BlendMode;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javax.imageio.ImageIO;
public class JavaFXApplication15 extends Application {
private void doWork() {
try {
// TODO code application logic here
File file = new File("C:\\Temp\\Mandibular\\MandibularsolidNOreferencepoints.gizmofill0.gizmoslice.png");
BufferedImage layerImage = ImageIO.read(file);
file = new File("C:\\Temp\\Mandibular\\MandibularsolidNOreferencepoints.gizmofill-1.gizmoslice.png");
BufferedImage fillImage = ImageIO.read(file);
WritableImage layerWritableImage = SwingFXUtils.toFXImage(layerImage, null);
WritableImage fillWritableImage = SwingFXUtils.toFXImage(fillImage, null);
WritableImage temp = copyImageOntoFillPattern(fillWritableImage, layerWritableImage);
File outputFile = new File("C:\\Temp\\Mandibular\\test.png");
ImageIO.write(SwingFXUtils.fromFXImage(temp, null), "png", outputFile);
} catch (IOException ex) {
Logger.getLogger(JavaFXApplication15.class.getName()).log(Level.SEVERE, null, ex);
}
}
private WritableImage copyImageOntoFillPattern(final WritableImage fillPatternImage, final WritableImage sourceImage) {
ImageView fillPatternView = new ImageView(fillPatternImage);
ImageView layerView = new ImageView(sourceImage);
layerView.setBlendMode(BlendMode.SRC_ATOP);
Group blend = new Group(fillPatternView, layerView);
blend.snapshot(null, sourceImage);
SnapshotParameters param = new SnapshotParameters();
final WritableImage snapshotCombined = blend.snapshot(param, null);
return snapshotCombined;
}
@Override
public void start(Stage primaryStage) {
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
doWork();
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}