Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1350bbfb36 | ||
|
|
d216bdf138 | ||
|
|
1ced263441 | ||
|
|
e9ea4c5248 | ||
|
|
ae7868d410 |
156
.agents/skills/openspec-apply-change/SKILL.md
Normal file
@@ -0,0 +1,156 @@
|
||||
---
|
||||
name: openspec-apply-change
|
||||
description: Implement tasks from an OpenSpec change. Use when the user wants to start implementing, continue implementation, or work through tasks.
|
||||
license: MIT
|
||||
compatibility: Requires openspec CLI.
|
||||
metadata:
|
||||
author: openspec
|
||||
version: "1.0"
|
||||
generatedBy: "1.3.1"
|
||||
---
|
||||
|
||||
Implement tasks from an OpenSpec change.
|
||||
|
||||
**Input**: Optionally specify a change name. If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
|
||||
|
||||
**Steps**
|
||||
|
||||
1. **Select the change**
|
||||
|
||||
If a name is provided, use it. Otherwise:
|
||||
- Infer from conversation context if the user mentioned a change
|
||||
- Auto-select if only one active change exists
|
||||
- If ambiguous, run `openspec list --json` to get available changes and use the **AskUserQuestion tool** to let the user select
|
||||
|
||||
Always announce: "Using change: <name>" and how to override (e.g., `/opsx:apply <other>`).
|
||||
|
||||
2. **Check status to understand the schema**
|
||||
```bash
|
||||
openspec status --change "<name>" --json
|
||||
```
|
||||
Parse the JSON to understand:
|
||||
- `schemaName`: The workflow being used (e.g., "spec-driven")
|
||||
- Which artifact contains the tasks (typically "tasks" for spec-driven, check status for others)
|
||||
|
||||
3. **Get apply instructions**
|
||||
|
||||
```bash
|
||||
openspec instructions apply --change "<name>" --json
|
||||
```
|
||||
|
||||
This returns:
|
||||
- `contextFiles`: artifact ID -> array of concrete file paths (varies by schema - could be proposal/specs/design/tasks or spec/tests/implementation/docs)
|
||||
- Progress (total, complete, remaining)
|
||||
- Task list with status
|
||||
- Dynamic instruction based on current state
|
||||
|
||||
**Handle states:**
|
||||
- If `state: "blocked"` (missing artifacts): show message, suggest using openspec-continue-change
|
||||
- If `state: "all_done"`: congratulate, suggest archive
|
||||
- Otherwise: proceed to implementation
|
||||
|
||||
4. **Read context files**
|
||||
|
||||
Read every file path listed under `contextFiles` from the apply instructions output.
|
||||
The files depend on the schema being used:
|
||||
- **spec-driven**: proposal, specs, design, tasks
|
||||
- Other schemas: follow the contextFiles from CLI output
|
||||
|
||||
5. **Show current progress**
|
||||
|
||||
Display:
|
||||
- Schema being used
|
||||
- Progress: "N/M tasks complete"
|
||||
- Remaining tasks overview
|
||||
- Dynamic instruction from CLI
|
||||
|
||||
6. **Implement tasks (loop until done or blocked)**
|
||||
|
||||
For each pending task:
|
||||
- Show which task is being worked on
|
||||
- Make the code changes required
|
||||
- Keep changes minimal and focused
|
||||
- Mark task complete in the tasks file: `- [ ]` → `- [x]`
|
||||
- Continue to next task
|
||||
|
||||
**Pause if:**
|
||||
- Task is unclear → ask for clarification
|
||||
- Implementation reveals a design issue → suggest updating artifacts
|
||||
- Error or blocker encountered → report and wait for guidance
|
||||
- User interrupts
|
||||
|
||||
7. **On completion or pause, show status**
|
||||
|
||||
Display:
|
||||
- Tasks completed this session
|
||||
- Overall progress: "N/M tasks complete"
|
||||
- If all done: suggest archive
|
||||
- If paused: explain why and wait for guidance
|
||||
|
||||
**Output During Implementation**
|
||||
|
||||
```
|
||||
## Implementing: <change-name> (schema: <schema-name>)
|
||||
|
||||
Working on task 3/7: <task description>
|
||||
[...implementation happening...]
|
||||
✓ Task complete
|
||||
|
||||
Working on task 4/7: <task description>
|
||||
[...implementation happening...]
|
||||
✓ Task complete
|
||||
```
|
||||
|
||||
**Output On Completion**
|
||||
|
||||
```
|
||||
## Implementation Complete
|
||||
|
||||
**Change:** <change-name>
|
||||
**Schema:** <schema-name>
|
||||
**Progress:** 7/7 tasks complete ✓
|
||||
|
||||
### Completed This Session
|
||||
- [x] Task 1
|
||||
- [x] Task 2
|
||||
...
|
||||
|
||||
All tasks complete! Ready to archive this change.
|
||||
```
|
||||
|
||||
**Output On Pause (Issue Encountered)**
|
||||
|
||||
```
|
||||
## Implementation Paused
|
||||
|
||||
**Change:** <change-name>
|
||||
**Schema:** <schema-name>
|
||||
**Progress:** 4/7 tasks complete
|
||||
|
||||
### Issue Encountered
|
||||
<description of the issue>
|
||||
|
||||
**Options:**
|
||||
1. <option 1>
|
||||
2. <option 2>
|
||||
3. Other approach
|
||||
|
||||
What would you like to do?
|
||||
```
|
||||
|
||||
**Guardrails**
|
||||
- Keep going through tasks until done or blocked
|
||||
- Always read context files before starting (from the apply instructions output)
|
||||
- If task is ambiguous, pause and ask before implementing
|
||||
- If implementation reveals issues, pause and suggest artifact updates
|
||||
- Keep code changes minimal and scoped to each task
|
||||
- Update task checkbox immediately after completing each task
|
||||
- Pause on errors, blockers, or unclear requirements - don't guess
|
||||
- Use contextFiles from CLI output, don't assume specific file names
|
||||
|
||||
**Fluid Workflow Integration**
|
||||
|
||||
This skill supports the "actions on a change" model:
|
||||
|
||||
- **Can be invoked anytime**: Before all artifacts are done (if tasks exist), after partial implementation, interleaved with other actions
|
||||
- **Allows artifact updates**: If implementation reveals design issues, suggest updating artifacts - not phase-locked, work fluidly
|
||||
114
.agents/skills/openspec-archive-change/SKILL.md
Normal file
@@ -0,0 +1,114 @@
|
||||
---
|
||||
name: openspec-archive-change
|
||||
description: Archive a completed change in the experimental workflow. Use when the user wants to finalize and archive a change after implementation is complete.
|
||||
license: MIT
|
||||
compatibility: Requires openspec CLI.
|
||||
metadata:
|
||||
author: openspec
|
||||
version: "1.0"
|
||||
generatedBy: "1.3.1"
|
||||
---
|
||||
|
||||
Archive a completed change in the experimental workflow.
|
||||
|
||||
**Input**: Optionally specify a change name. If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
|
||||
|
||||
**Steps**
|
||||
|
||||
1. **If no change name provided, prompt for selection**
|
||||
|
||||
Run `openspec list --json` to get available changes. Use the **AskUserQuestion tool** to let the user select.
|
||||
|
||||
Show only active changes (not already archived).
|
||||
Include the schema used for each change if available.
|
||||
|
||||
**IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
|
||||
|
||||
2. **Check artifact completion status**
|
||||
|
||||
Run `openspec status --change "<name>" --json` to check artifact completion.
|
||||
|
||||
Parse the JSON to understand:
|
||||
- `schemaName`: The workflow being used
|
||||
- `artifacts`: List of artifacts with their status (`done` or other)
|
||||
|
||||
**If any artifacts are not `done`:**
|
||||
- Display warning listing incomplete artifacts
|
||||
- Use **AskUserQuestion tool** to confirm user wants to proceed
|
||||
- Proceed if user confirms
|
||||
|
||||
3. **Check task completion status**
|
||||
|
||||
Read the tasks file (typically `tasks.md`) to check for incomplete tasks.
|
||||
|
||||
Count tasks marked with `- [ ]` (incomplete) vs `- [x]` (complete).
|
||||
|
||||
**If incomplete tasks found:**
|
||||
- Display warning showing count of incomplete tasks
|
||||
- Use **AskUserQuestion tool** to confirm user wants to proceed
|
||||
- Proceed if user confirms
|
||||
|
||||
**If no tasks file exists:** Proceed without task-related warning.
|
||||
|
||||
4. **Assess delta spec sync state**
|
||||
|
||||
Check for delta specs at `openspec/changes/<name>/specs/`. If none exist, proceed without sync prompt.
|
||||
|
||||
**If delta specs exist:**
|
||||
- Compare each delta spec with its corresponding main spec at `openspec/specs/<capability>/spec.md`
|
||||
- Determine what changes would be applied (adds, modifications, removals, renames)
|
||||
- Show a combined summary before prompting
|
||||
|
||||
**Prompt options:**
|
||||
- If changes needed: "Sync now (recommended)", "Archive without syncing"
|
||||
- If already synced: "Archive now", "Sync anyway", "Cancel"
|
||||
|
||||
If user chooses sync, use Task tool (subagent_type: "general-purpose", prompt: "Use Skill tool to invoke openspec-sync-specs for change '<name>'. Delta spec analysis: <include the analyzed delta spec summary>"). Proceed to archive regardless of choice.
|
||||
|
||||
5. **Perform the archive**
|
||||
|
||||
Create the archive directory if it doesn't exist:
|
||||
```bash
|
||||
mkdir -p openspec/changes/archive
|
||||
```
|
||||
|
||||
Generate target name using current date: `YYYY-MM-DD-<change-name>`
|
||||
|
||||
**Check if target already exists:**
|
||||
- If yes: Fail with error, suggest renaming existing archive or using different date
|
||||
- If no: Move the change directory to archive
|
||||
|
||||
```bash
|
||||
mv openspec/changes/<name> openspec/changes/archive/YYYY-MM-DD-<name>
|
||||
```
|
||||
|
||||
6. **Display summary**
|
||||
|
||||
Show archive completion summary including:
|
||||
- Change name
|
||||
- Schema that was used
|
||||
- Archive location
|
||||
- Whether specs were synced (if applicable)
|
||||
- Note about any warnings (incomplete artifacts/tasks)
|
||||
|
||||
**Output On Success**
|
||||
|
||||
```
|
||||
## Archive Complete
|
||||
|
||||
**Change:** <change-name>
|
||||
**Schema:** <schema-name>
|
||||
**Archived to:** openspec/changes/archive/YYYY-MM-DD-<name>/
|
||||
**Specs:** ✓ Synced to main specs (or "No delta specs" or "Sync skipped")
|
||||
|
||||
All artifacts complete. All tasks complete.
|
||||
```
|
||||
|
||||
**Guardrails**
|
||||
- Always prompt for change selection if not provided
|
||||
- Use artifact graph (openspec status --json) for completion checking
|
||||
- Don't block archive on warnings - just inform and confirm
|
||||
- Preserve .openspec.yaml when moving to archive (it moves with the directory)
|
||||
- Show clear summary of what happened
|
||||
- If sync is requested, use openspec-sync-specs approach (agent-driven)
|
||||
- If delta specs exist, always run the sync assessment and show the combined summary before prompting
|
||||
288
.agents/skills/openspec-explore/SKILL.md
Normal file
@@ -0,0 +1,288 @@
|
||||
---
|
||||
name: openspec-explore
|
||||
description: Enter explore mode - a thinking partner for exploring ideas, investigating problems, and clarifying requirements. Use when the user wants to think through something before or during a change.
|
||||
license: MIT
|
||||
compatibility: Requires openspec CLI.
|
||||
metadata:
|
||||
author: openspec
|
||||
version: "1.0"
|
||||
generatedBy: "1.3.1"
|
||||
---
|
||||
|
||||
Enter explore mode. Think deeply. Visualize freely. Follow the conversation wherever it goes.
|
||||
|
||||
**IMPORTANT: Explore mode is for thinking, not implementing.** You may read files, search code, and investigate the codebase, but you must NEVER write code or implement features. If the user asks you to implement something, remind them to exit explore mode first and create a change proposal. You MAY create OpenSpec artifacts (proposals, designs, specs) if the user asks—that's capturing thinking, not implementing.
|
||||
|
||||
**This is a stance, not a workflow.** There are no fixed steps, no required sequence, no mandatory outputs. You're a thinking partner helping the user explore.
|
||||
|
||||
---
|
||||
|
||||
## The Stance
|
||||
|
||||
- **Curious, not prescriptive** - Ask questions that emerge naturally, don't follow a script
|
||||
- **Open threads, not interrogations** - Surface multiple interesting directions and let the user follow what resonates. Don't funnel them through a single path of questions.
|
||||
- **Visual** - Use ASCII diagrams liberally when they'd help clarify thinking
|
||||
- **Adaptive** - Follow interesting threads, pivot when new information emerges
|
||||
- **Patient** - Don't rush to conclusions, let the shape of the problem emerge
|
||||
- **Grounded** - Explore the actual codebase when relevant, don't just theorize
|
||||
|
||||
---
|
||||
|
||||
## What You Might Do
|
||||
|
||||
Depending on what the user brings, you might:
|
||||
|
||||
**Explore the problem space**
|
||||
- Ask clarifying questions that emerge from what they said
|
||||
- Challenge assumptions
|
||||
- Reframe the problem
|
||||
- Find analogies
|
||||
|
||||
**Investigate the codebase**
|
||||
- Map existing architecture relevant to the discussion
|
||||
- Find integration points
|
||||
- Identify patterns already in use
|
||||
- Surface hidden complexity
|
||||
|
||||
**Compare options**
|
||||
- Brainstorm multiple approaches
|
||||
- Build comparison tables
|
||||
- Sketch tradeoffs
|
||||
- Recommend a path (if asked)
|
||||
|
||||
**Visualize**
|
||||
```
|
||||
┌─────────────────────────────────────────┐
|
||||
│ Use ASCII diagrams liberally │
|
||||
├─────────────────────────────────────────┤
|
||||
│ │
|
||||
│ ┌────────┐ ┌────────┐ │
|
||||
│ │ State │────────▶│ State │ │
|
||||
│ │ A │ │ B │ │
|
||||
│ └────────┘ └────────┘ │
|
||||
│ │
|
||||
│ System diagrams, state machines, │
|
||||
│ data flows, architecture sketches, │
|
||||
│ dependency graphs, comparison tables │
|
||||
│ │
|
||||
└─────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
**Surface risks and unknowns**
|
||||
- Identify what could go wrong
|
||||
- Find gaps in understanding
|
||||
- Suggest spikes or investigations
|
||||
|
||||
---
|
||||
|
||||
## OpenSpec Awareness
|
||||
|
||||
You have full context of the OpenSpec system. Use it naturally, don't force it.
|
||||
|
||||
### Check for context
|
||||
|
||||
At the start, quickly check what exists:
|
||||
```bash
|
||||
openspec list --json
|
||||
```
|
||||
|
||||
This tells you:
|
||||
- If there are active changes
|
||||
- Their names, schemas, and status
|
||||
- What the user might be working on
|
||||
|
||||
### When no change exists
|
||||
|
||||
Think freely. When insights crystallize, you might offer:
|
||||
|
||||
- "This feels solid enough to start a change. Want me to create a proposal?"
|
||||
- Or keep exploring - no pressure to formalize
|
||||
|
||||
### When a change exists
|
||||
|
||||
If the user mentions a change or you detect one is relevant:
|
||||
|
||||
1. **Read existing artifacts for context**
|
||||
- `openspec/changes/<name>/proposal.md`
|
||||
- `openspec/changes/<name>/design.md`
|
||||
- `openspec/changes/<name>/tasks.md`
|
||||
- etc.
|
||||
|
||||
2. **Reference them naturally in conversation**
|
||||
- "Your design mentions using Redis, but we just realized SQLite fits better..."
|
||||
- "The proposal scopes this to premium users, but we're now thinking everyone..."
|
||||
|
||||
3. **Offer to capture when decisions are made**
|
||||
|
||||
| Insight Type | Where to Capture |
|
||||
|----------------------------|--------------------------------|
|
||||
| New requirement discovered | `specs/<capability>/spec.md` |
|
||||
| Requirement changed | `specs/<capability>/spec.md` |
|
||||
| Design decision made | `design.md` |
|
||||
| Scope changed | `proposal.md` |
|
||||
| New work identified | `tasks.md` |
|
||||
| Assumption invalidated | Relevant artifact |
|
||||
|
||||
Example offers:
|
||||
- "That's a design decision. Capture it in design.md?"
|
||||
- "This is a new requirement. Add it to specs?"
|
||||
- "This changes scope. Update the proposal?"
|
||||
|
||||
4. **The user decides** - Offer and move on. Don't pressure. Don't auto-capture.
|
||||
|
||||
---
|
||||
|
||||
## What You Don't Have To Do
|
||||
|
||||
- Follow a script
|
||||
- Ask the same questions every time
|
||||
- Produce a specific artifact
|
||||
- Reach a conclusion
|
||||
- Stay on topic if a tangent is valuable
|
||||
- Be brief (this is thinking time)
|
||||
|
||||
---
|
||||
|
||||
## Handling Different Entry Points
|
||||
|
||||
**User brings a vague idea:**
|
||||
```
|
||||
User: I'm thinking about adding real-time collaboration
|
||||
|
||||
You: Real-time collab is a big space. Let me think about this...
|
||||
|
||||
COLLABORATION SPECTRUM
|
||||
════════════════════════════════════════════
|
||||
|
||||
Awareness Coordination Sync
|
||||
│ │ │
|
||||
▼ ▼ ▼
|
||||
┌────────┐ ┌────────┐ ┌────────┐
|
||||
│Presence│ │Cursors │ │ CRDT │
|
||||
│ "3 │ │ Multi │ │Conflict│
|
||||
│online" │ │ select │ │ free │
|
||||
└────────┘ └────────┘ └────────┘
|
||||
│ │ │
|
||||
trivial moderate complex
|
||||
|
||||
Where's your head at?
|
||||
```
|
||||
|
||||
**User brings a specific problem:**
|
||||
```
|
||||
User: The auth system is a mess
|
||||
|
||||
You: [reads codebase]
|
||||
|
||||
┌─────────────────────────────────────────────┐
|
||||
│ CURRENT AUTH FLOW │
|
||||
└─────────────────────────────────────────────┘
|
||||
│
|
||||
┌─────────────┼─────────────┐
|
||||
▼ ▼ ▼
|
||||
┌─────────┐ ┌─────────┐ ┌─────────┐
|
||||
│ Google │ │ GitHub │ │ Email │
|
||||
│ OAuth │ │ OAuth │ │ Magic │
|
||||
└────┬────┘ └────┬────┘ └────┬────┘
|
||||
│ │ │
|
||||
└─────────────┼─────────────┘
|
||||
▼
|
||||
┌───────────┐
|
||||
│ Session │
|
||||
└─────┬─────┘
|
||||
│
|
||||
▼
|
||||
┌───────────┐
|
||||
│ Perms │
|
||||
└───────────┘
|
||||
|
||||
I see three tangles. Which one's burning?
|
||||
```
|
||||
|
||||
**User is stuck mid-implementation:**
|
||||
```
|
||||
User: /opsx:explore add-auth-system
|
||||
The OAuth integration is more complex than expected
|
||||
|
||||
You: [reads change artifacts]
|
||||
|
||||
You're on task 4: "Implement OAuth flow"
|
||||
|
||||
Let me trace what's involved...
|
||||
|
||||
[draws diagram, explores options, suggests paths]
|
||||
|
||||
Want to update the design to reflect this?
|
||||
Or add a spike task to investigate?
|
||||
```
|
||||
|
||||
**User wants to compare options:**
|
||||
```
|
||||
User: Should we use Postgres or SQLite?
|
||||
|
||||
You: Generic answer is boring. What's the context?
|
||||
|
||||
User: A CLI tool that tracks local dev environments
|
||||
|
||||
You: That changes everything.
|
||||
|
||||
┌─────────────────────────────────────────────────┐
|
||||
│ CLI TOOL DATA STORAGE │
|
||||
└─────────────────────────────────────────────────┘
|
||||
|
||||
Key constraints:
|
||||
• No daemon running
|
||||
• Must work offline
|
||||
• Single user
|
||||
|
||||
SQLite Postgres
|
||||
Deployment embedded ✓ needs server ✗
|
||||
Offline yes ✓ no ✗
|
||||
Single file yes ✓ no ✗
|
||||
|
||||
SQLite. Not even close.
|
||||
|
||||
Unless... is there a sync component?
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Ending Discovery
|
||||
|
||||
There's no required ending. Discovery might:
|
||||
|
||||
- **Flow into a proposal**: "Ready to start? I can create a change proposal."
|
||||
- **Result in artifact updates**: "Updated design.md with these decisions"
|
||||
- **Just provide clarity**: User has what they need, moves on
|
||||
- **Continue later**: "We can pick this up anytime"
|
||||
|
||||
When it feels like things are crystallizing, you might summarize:
|
||||
|
||||
```
|
||||
## What We Figured Out
|
||||
|
||||
**The problem**: [crystallized understanding]
|
||||
|
||||
**The approach**: [if one emerged]
|
||||
|
||||
**Open questions**: [if any remain]
|
||||
|
||||
**Next steps** (if ready):
|
||||
- Create a change proposal
|
||||
- Keep exploring: just keep talking
|
||||
```
|
||||
|
||||
But this summary is optional. Sometimes the thinking IS the value.
|
||||
|
||||
---
|
||||
|
||||
## Guardrails
|
||||
|
||||
- **Don't implement** - Never write code or implement features. Creating OpenSpec artifacts is fine, writing application code is not.
|
||||
- **Don't fake understanding** - If something is unclear, dig deeper
|
||||
- **Don't rush** - Discovery is thinking time, not task time
|
||||
- **Don't force structure** - Let patterns emerge naturally
|
||||
- **Don't auto-capture** - Offer to save insights, don't just do it
|
||||
- **Do visualize** - A good diagram is worth many paragraphs
|
||||
- **Do explore the codebase** - Ground discussions in reality
|
||||
- **Do question assumptions** - Including the user's and your own
|
||||
110
.agents/skills/openspec-propose/SKILL.md
Normal file
@@ -0,0 +1,110 @@
|
||||
---
|
||||
name: openspec-propose
|
||||
description: Propose a new change with all artifacts generated in one step. Use when the user wants to quickly describe what they want to build and get a complete proposal with design, specs, and tasks ready for implementation.
|
||||
license: MIT
|
||||
compatibility: Requires openspec CLI.
|
||||
metadata:
|
||||
author: openspec
|
||||
version: "1.0"
|
||||
generatedBy: "1.3.1"
|
||||
---
|
||||
|
||||
Propose a new change - create the change and generate all artifacts in one step.
|
||||
|
||||
I'll create a change with artifacts:
|
||||
- proposal.md (what & why)
|
||||
- design.md (how)
|
||||
- tasks.md (implementation steps)
|
||||
|
||||
When ready to implement, run /opsx:apply
|
||||
|
||||
---
|
||||
|
||||
**Input**: The user's request should include a change name (kebab-case) OR a description of what they want to build.
|
||||
|
||||
**Steps**
|
||||
|
||||
1. **If no clear input provided, ask what they want to build**
|
||||
|
||||
Use the **AskUserQuestion tool** (open-ended, no preset options) to ask:
|
||||
> "What change do you want to work on? Describe what you want to build or fix."
|
||||
|
||||
From their description, derive a kebab-case name (e.g., "add user authentication" → `add-user-auth`).
|
||||
|
||||
**IMPORTANT**: Do NOT proceed without understanding what the user wants to build.
|
||||
|
||||
2. **Create the change directory**
|
||||
```bash
|
||||
openspec new change "<name>"
|
||||
```
|
||||
This creates a scaffolded change at `openspec/changes/<name>/` with `.openspec.yaml`.
|
||||
|
||||
3. **Get the artifact build order**
|
||||
```bash
|
||||
openspec status --change "<name>" --json
|
||||
```
|
||||
Parse the JSON to get:
|
||||
- `applyRequires`: array of artifact IDs needed before implementation (e.g., `["tasks"]`)
|
||||
- `artifacts`: list of all artifacts with their status and dependencies
|
||||
|
||||
4. **Create artifacts in sequence until apply-ready**
|
||||
|
||||
Use the **TodoWrite tool** to track progress through the artifacts.
|
||||
|
||||
Loop through artifacts in dependency order (artifacts with no pending dependencies first):
|
||||
|
||||
a. **For each artifact that is `ready` (dependencies satisfied)**:
|
||||
- Get instructions:
|
||||
```bash
|
||||
openspec instructions <artifact-id> --change "<name>" --json
|
||||
```
|
||||
- The instructions JSON includes:
|
||||
- `context`: Project background (constraints for you - do NOT include in output)
|
||||
- `rules`: Artifact-specific rules (constraints for you - do NOT include in output)
|
||||
- `template`: The structure to use for your output file
|
||||
- `instruction`: Schema-specific guidance for this artifact type
|
||||
- `outputPath`: Where to write the artifact
|
||||
- `dependencies`: Completed artifacts to read for context
|
||||
- Read any completed dependency files for context
|
||||
- Create the artifact file using `template` as the structure
|
||||
- Apply `context` and `rules` as constraints - but do NOT copy them into the file
|
||||
- Show brief progress: "Created <artifact-id>"
|
||||
|
||||
b. **Continue until all `applyRequires` artifacts are complete**
|
||||
- After creating each artifact, re-run `openspec status --change "<name>" --json`
|
||||
- Check if every artifact ID in `applyRequires` has `status: "done"` in the artifacts array
|
||||
- Stop when all `applyRequires` artifacts are done
|
||||
|
||||
c. **If an artifact requires user input** (unclear context):
|
||||
- Use **AskUserQuestion tool** to clarify
|
||||
- Then continue with creation
|
||||
|
||||
5. **Show final status**
|
||||
```bash
|
||||
openspec status --change "<name>"
|
||||
```
|
||||
|
||||
**Output**
|
||||
|
||||
After completing all artifacts, summarize:
|
||||
- Change name and location
|
||||
- List of artifacts created with brief descriptions
|
||||
- What's ready: "All artifacts created! Ready for implementation."
|
||||
- Prompt: "Run `/opsx:apply` or ask me to implement to start working on the tasks."
|
||||
|
||||
**Artifact Creation Guidelines**
|
||||
|
||||
- Follow the `instruction` field from `openspec instructions` for each artifact type
|
||||
- The schema defines what each artifact should contain - follow it
|
||||
- Read dependency artifacts for context before creating new ones
|
||||
- Use `template` as the structure for your output file - fill in its sections
|
||||
- **IMPORTANT**: `context` and `rules` are constraints for YOU, not content for the file
|
||||
- Do NOT copy `<context>`, `<rules>`, `<project_context>` blocks into the artifact
|
||||
- These guide what you write, but should never appear in the output
|
||||
|
||||
**Guardrails**
|
||||
- Create ALL artifacts needed for implementation (as defined by schema's `apply.requires`)
|
||||
- Always read dependency artifacts before creating a new one
|
||||
- If context is critically unclear, ask the user - but prefer making reasonable decisions to keep momentum
|
||||
- If a change with that name already exists, ask if user wants to continue it or create a new one
|
||||
- Verify each artifact file exists after writing before proceeding to next
|
||||
156
.agents/skills/source-command-opsx-apply/SKILL.md
Normal file
@@ -0,0 +1,156 @@
|
||||
---
|
||||
name: "source-command-opsx-apply"
|
||||
description: "Implement tasks from an OpenSpec change (Experimental)"
|
||||
---
|
||||
|
||||
# source-command-opsx-apply
|
||||
|
||||
Use this skill when the user asks to run the migrated source command `opsx-apply`.
|
||||
|
||||
## Command Template
|
||||
|
||||
Implement tasks from an OpenSpec change.
|
||||
|
||||
**Input**: Optionally specify a change name (e.g., `/opsx:apply add-auth`). If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
|
||||
|
||||
**Steps**
|
||||
|
||||
1. **Select the change**
|
||||
|
||||
If a name is provided, use it. Otherwise:
|
||||
- Infer from conversation context if the user mentioned a change
|
||||
- Auto-select if only one active change exists
|
||||
- If ambiguous, run `openspec list --json` to get available changes and use the **AskUserQuestion tool** to let the user select
|
||||
|
||||
Always announce: "Using change: <name>" and how to override (e.g., `/opsx:apply <other>`).
|
||||
|
||||
2. **Check status to understand the schema**
|
||||
```bash
|
||||
openspec status --change "<name>" --json
|
||||
```
|
||||
Parse the JSON to understand:
|
||||
- `schemaName`: The workflow being used (e.g., "spec-driven")
|
||||
- Which artifact contains the tasks (typically "tasks" for spec-driven, check status for others)
|
||||
|
||||
3. **Get apply instructions**
|
||||
|
||||
```bash
|
||||
openspec instructions apply --change "<name>" --json
|
||||
```
|
||||
|
||||
This returns:
|
||||
- `contextFiles`: artifact ID -> array of concrete file paths (varies by schema)
|
||||
- Progress (total, complete, remaining)
|
||||
- Task list with status
|
||||
- Dynamic instruction based on current state
|
||||
|
||||
**Handle states:**
|
||||
- If `state: "blocked"` (missing artifacts): show message, suggest using `/opsx:continue`
|
||||
- If `state: "all_done"`: congratulate, suggest archive
|
||||
- Otherwise: proceed to implementation
|
||||
|
||||
4. **Read context files**
|
||||
|
||||
Read every file path listed under `contextFiles` from the apply instructions output.
|
||||
The files depend on the schema being used:
|
||||
- **spec-driven**: proposal, specs, design, tasks
|
||||
- Other schemas: follow the contextFiles from CLI output
|
||||
|
||||
5. **Show current progress**
|
||||
|
||||
Display:
|
||||
- Schema being used
|
||||
- Progress: "N/M tasks complete"
|
||||
- Remaining tasks overview
|
||||
- Dynamic instruction from CLI
|
||||
|
||||
6. **Implement tasks (loop until done or blocked)**
|
||||
|
||||
For each pending task:
|
||||
- Show which task is being worked on
|
||||
- Make the code changes required
|
||||
- Keep changes minimal and focused
|
||||
- Mark task complete in the tasks file: `- [ ]` → `- [x]`
|
||||
- Continue to next task
|
||||
|
||||
**Pause if:**
|
||||
- Task is unclear → ask for clarification
|
||||
- Implementation reveals a design issue → suggest updating artifacts
|
||||
- Error or blocker encountered → report and wait for guidance
|
||||
- User interrupts
|
||||
|
||||
7. **On completion or pause, show status**
|
||||
|
||||
Display:
|
||||
- Tasks completed this session
|
||||
- Overall progress: "N/M tasks complete"
|
||||
- If all done: suggest archive
|
||||
- If paused: explain why and wait for guidance
|
||||
|
||||
**Output During Implementation**
|
||||
|
||||
```
|
||||
## Implementing: <change-name> (schema: <schema-name>)
|
||||
|
||||
Working on task 3/7: <task description>
|
||||
[...implementation happening...]
|
||||
✓ Task complete
|
||||
|
||||
Working on task 4/7: <task description>
|
||||
[...implementation happening...]
|
||||
✓ Task complete
|
||||
```
|
||||
|
||||
**Output On Completion**
|
||||
|
||||
```
|
||||
## Implementation Complete
|
||||
|
||||
**Change:** <change-name>
|
||||
**Schema:** <schema-name>
|
||||
**Progress:** 7/7 tasks complete ✓
|
||||
|
||||
### Completed This Session
|
||||
- [x] Task 1
|
||||
- [x] Task 2
|
||||
...
|
||||
|
||||
All tasks complete! You can archive this change with `/opsx:archive`.
|
||||
```
|
||||
|
||||
**Output On Pause (Issue Encountered)**
|
||||
|
||||
```
|
||||
## Implementation Paused
|
||||
|
||||
**Change:** <change-name>
|
||||
**Schema:** <schema-name>
|
||||
**Progress:** 4/7 tasks complete
|
||||
|
||||
### Issue Encountered
|
||||
<description of the issue>
|
||||
|
||||
**Options:**
|
||||
1. <option 1>
|
||||
2. <option 2>
|
||||
3. Other approach
|
||||
|
||||
What would you like to do?
|
||||
```
|
||||
|
||||
**Guardrails**
|
||||
- Keep going through tasks until done or blocked
|
||||
- Always read context files before starting (from the apply instructions output)
|
||||
- If task is ambiguous, pause and ask before implementing
|
||||
- If implementation reveals issues, pause and suggest artifact updates
|
||||
- Keep code changes minimal and scoped to each task
|
||||
- Update task checkbox immediately after completing each task
|
||||
- Pause on errors, blockers, or unclear requirements - don't guess
|
||||
- Use contextFiles from CLI output, don't assume specific file names
|
||||
|
||||
**Fluid Workflow Integration**
|
||||
|
||||
This skill supports the "actions on a change" model:
|
||||
|
||||
- **Can be invoked anytime**: Before all artifacts are done (if tasks exist), after partial implementation, interleaved with other actions
|
||||
- **Allows artifact updates**: If implementation reveals design issues, suggest updating artifacts - not phase-locked, work fluidly
|
||||
161
.agents/skills/source-command-opsx-archive/SKILL.md
Normal file
@@ -0,0 +1,161 @@
|
||||
---
|
||||
name: "source-command-opsx-archive"
|
||||
description: "Archive a completed change in the experimental workflow"
|
||||
---
|
||||
|
||||
# source-command-opsx-archive
|
||||
|
||||
Use this skill when the user asks to run the migrated source command `opsx-archive`.
|
||||
|
||||
## Command Template
|
||||
|
||||
Archive a completed change in the experimental workflow.
|
||||
|
||||
**Input**: Optionally specify a change name after `/opsx:archive` (e.g., `/opsx:archive add-auth`). If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
|
||||
|
||||
**Steps**
|
||||
|
||||
1. **If no change name provided, prompt for selection**
|
||||
|
||||
Run `openspec list --json` to get available changes. Use the **AskUserQuestion tool** to let the user select.
|
||||
|
||||
Show only active changes (not already archived).
|
||||
Include the schema used for each change if available.
|
||||
|
||||
**IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
|
||||
|
||||
2. **Check artifact completion status**
|
||||
|
||||
Run `openspec status --change "<name>" --json` to check artifact completion.
|
||||
|
||||
Parse the JSON to understand:
|
||||
- `schemaName`: The workflow being used
|
||||
- `artifacts`: List of artifacts with their status (`done` or other)
|
||||
|
||||
**If any artifacts are not `done`:**
|
||||
- Display warning listing incomplete artifacts
|
||||
- Prompt user for confirmation to continue
|
||||
- Proceed if user confirms
|
||||
|
||||
3. **Check task completion status**
|
||||
|
||||
Read the tasks file (typically `tasks.md`) to check for incomplete tasks.
|
||||
|
||||
Count tasks marked with `- [ ]` (incomplete) vs `- [x]` (complete).
|
||||
|
||||
**If incomplete tasks found:**
|
||||
- Display warning showing count of incomplete tasks
|
||||
- Prompt user for confirmation to continue
|
||||
- Proceed if user confirms
|
||||
|
||||
**If no tasks file exists:** Proceed without task-related warning.
|
||||
|
||||
4. **Assess delta spec sync state**
|
||||
|
||||
Check for delta specs at `openspec/changes/<name>/specs/`. If none exist, proceed without sync prompt.
|
||||
|
||||
**If delta specs exist:**
|
||||
- Compare each delta spec with its corresponding main spec at `openspec/specs/<capability>/spec.md`
|
||||
- Determine what changes would be applied (adds, modifications, removals, renames)
|
||||
- Show a combined summary before prompting
|
||||
|
||||
**Prompt options:**
|
||||
- If changes needed: "Sync now (recommended)", "Archive without syncing"
|
||||
- If already synced: "Archive now", "Sync anyway", "Cancel"
|
||||
|
||||
If user chooses sync, use Task tool (subagent_type: "general-purpose", prompt: "Use Skill tool to invoke openspec-sync-specs for change '<name>'. Delta spec analysis: <include the analyzed delta spec summary>"). Proceed to archive regardless of choice.
|
||||
|
||||
5. **Perform the archive**
|
||||
|
||||
Create the archive directory if it doesn't exist:
|
||||
```bash
|
||||
mkdir -p openspec/changes/archive
|
||||
```
|
||||
|
||||
Generate target name using current date: `YYYY-MM-DD-<change-name>`
|
||||
|
||||
**Check if target already exists:**
|
||||
- If yes: Fail with error, suggest renaming existing archive or using different date
|
||||
- If no: Move the change directory to archive
|
||||
|
||||
```bash
|
||||
mv openspec/changes/<name> openspec/changes/archive/YYYY-MM-DD-<name>
|
||||
```
|
||||
|
||||
6. **Display summary**
|
||||
|
||||
Show archive completion summary including:
|
||||
- Change name
|
||||
- Schema that was used
|
||||
- Archive location
|
||||
- Spec sync status (synced / sync skipped / no delta specs)
|
||||
- Note about any warnings (incomplete artifacts/tasks)
|
||||
|
||||
**Output On Success**
|
||||
|
||||
```
|
||||
## Archive Complete
|
||||
|
||||
**Change:** <change-name>
|
||||
**Schema:** <schema-name>
|
||||
**Archived to:** openspec/changes/archive/YYYY-MM-DD-<name>/
|
||||
**Specs:** ✓ Synced to main specs
|
||||
|
||||
All artifacts complete. All tasks complete.
|
||||
```
|
||||
|
||||
**Output On Success (No Delta Specs)**
|
||||
|
||||
```
|
||||
## Archive Complete
|
||||
|
||||
**Change:** <change-name>
|
||||
**Schema:** <schema-name>
|
||||
**Archived to:** openspec/changes/archive/YYYY-MM-DD-<name>/
|
||||
**Specs:** No delta specs
|
||||
|
||||
All artifacts complete. All tasks complete.
|
||||
```
|
||||
|
||||
**Output On Success With Warnings**
|
||||
|
||||
```
|
||||
## Archive Complete (with warnings)
|
||||
|
||||
**Change:** <change-name>
|
||||
**Schema:** <schema-name>
|
||||
**Archived to:** openspec/changes/archive/YYYY-MM-DD-<name>/
|
||||
**Specs:** Sync skipped (user chose to skip)
|
||||
|
||||
**Warnings:**
|
||||
- Archived with 2 incomplete artifacts
|
||||
- Archived with 3 incomplete tasks
|
||||
- Delta spec sync was skipped (user chose to skip)
|
||||
|
||||
Review the archive if this was not intentional.
|
||||
```
|
||||
|
||||
**Output On Error (Archive Exists)**
|
||||
|
||||
```
|
||||
## Archive Failed
|
||||
|
||||
**Change:** <change-name>
|
||||
**Target:** openspec/changes/archive/YYYY-MM-DD-<name>/
|
||||
|
||||
Target archive directory already exists.
|
||||
|
||||
**Options:**
|
||||
1. Rename the existing archive
|
||||
2. Delete the existing archive if it's a duplicate
|
||||
3. Wait until a different date to archive
|
||||
```
|
||||
|
||||
**Guardrails**
|
||||
- Always prompt for change selection if not provided
|
||||
- Use artifact graph (openspec status --json) for completion checking
|
||||
- Don't block archive on warnings - just inform and confirm
|
||||
- Preserve .openspec.yaml when moving to archive (it moves with the directory)
|
||||
- Show clear summary of what happened
|
||||
- If sync is requested, use the Skill tool to invoke `openspec-sync-specs` (agent-driven)
|
||||
- If delta specs exist, always run the sync assessment and show the combined summary before prompting
|
||||
177
.agents/skills/source-command-opsx-explore/SKILL.md
Normal file
@@ -0,0 +1,177 @@
|
||||
---
|
||||
name: "source-command-opsx-explore"
|
||||
description: "Enter explore mode - think through ideas, investigate problems, clarify requirements"
|
||||
---
|
||||
|
||||
# source-command-opsx-explore
|
||||
|
||||
Use this skill when the user asks to run the migrated source command `opsx-explore`.
|
||||
|
||||
## Command Template
|
||||
|
||||
Enter explore mode. Think deeply. Visualize freely. Follow the conversation wherever it goes.
|
||||
|
||||
**IMPORTANT: Explore mode is for thinking, not implementing.** You may read files, search code, and investigate the codebase, but you must NEVER write code or implement features. If the user asks you to implement something, remind them to exit explore mode first and create a change proposal. You MAY create OpenSpec artifacts (proposals, designs, specs) if the user asks—that's capturing thinking, not implementing.
|
||||
|
||||
**This is a stance, not a workflow.** There are no fixed steps, no required sequence, no mandatory outputs. You're a thinking partner helping the user explore.
|
||||
|
||||
**Input**: The argument after `/opsx:explore` is whatever the user wants to think about. Could be:
|
||||
- A vague idea: "real-time collaboration"
|
||||
- A specific problem: "the auth system is getting unwieldy"
|
||||
- A change name: "add-dark-mode" (to explore in context of that change)
|
||||
- A comparison: "postgres vs sqlite for this"
|
||||
- Nothing (just enter explore mode)
|
||||
|
||||
---
|
||||
|
||||
## The Stance
|
||||
|
||||
- **Curious, not prescriptive** - Ask questions that emerge naturally, don't follow a script
|
||||
- **Open threads, not interrogations** - Surface multiple interesting directions and let the user follow what resonates. Don't funnel them through a single path of questions.
|
||||
- **Visual** - Use ASCII diagrams liberally when they'd help clarify thinking
|
||||
- **Adaptive** - Follow interesting threads, pivot when new information emerges
|
||||
- **Patient** - Don't rush to conclusions, let the shape of the problem emerge
|
||||
- **Grounded** - Explore the actual codebase when relevant, don't just theorize
|
||||
|
||||
---
|
||||
|
||||
## What You Might Do
|
||||
|
||||
Depending on what the user brings, you might:
|
||||
|
||||
**Explore the problem space**
|
||||
- Ask clarifying questions that emerge from what they said
|
||||
- Challenge assumptions
|
||||
- Reframe the problem
|
||||
- Find analogies
|
||||
|
||||
**Investigate the codebase**
|
||||
- Map existing architecture relevant to the discussion
|
||||
- Find integration points
|
||||
- Identify patterns already in use
|
||||
- Surface hidden complexity
|
||||
|
||||
**Compare options**
|
||||
- Brainstorm multiple approaches
|
||||
- Build comparison tables
|
||||
- Sketch tradeoffs
|
||||
- Recommend a path (if asked)
|
||||
|
||||
**Visualize**
|
||||
```
|
||||
┌─────────────────────────────────────────┐
|
||||
│ Use ASCII diagrams liberally │
|
||||
├─────────────────────────────────────────┤
|
||||
│ │
|
||||
│ ┌────────┐ ┌────────┐ │
|
||||
│ │ State │────────▶│ State │ │
|
||||
│ │ A │ │ B │ │
|
||||
│ └────────┘ └────────┘ │
|
||||
│ │
|
||||
│ System diagrams, state machines, │
|
||||
│ data flows, architecture sketches, │
|
||||
│ dependency graphs, comparison tables │
|
||||
│ │
|
||||
└─────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
**Surface risks and unknowns**
|
||||
- Identify what could go wrong
|
||||
- Find gaps in understanding
|
||||
- Suggest spikes or investigations
|
||||
|
||||
---
|
||||
|
||||
## OpenSpec Awareness
|
||||
|
||||
You have full context of the OpenSpec system. Use it naturally, don't force it.
|
||||
|
||||
### Check for context
|
||||
|
||||
At the start, quickly check what exists:
|
||||
```bash
|
||||
openspec list --json
|
||||
```
|
||||
|
||||
This tells you:
|
||||
- If there are active changes
|
||||
- Their names, schemas, and status
|
||||
- What the user might be working on
|
||||
|
||||
If the user mentioned a specific change name, read its artifacts for context.
|
||||
|
||||
### When no change exists
|
||||
|
||||
Think freely. When insights crystallize, you might offer:
|
||||
|
||||
- "This feels solid enough to start a change. Want me to create a proposal?"
|
||||
- Or keep exploring - no pressure to formalize
|
||||
|
||||
### When a change exists
|
||||
|
||||
If the user mentions a change or you detect one is relevant:
|
||||
|
||||
1. **Read existing artifacts for context**
|
||||
- `openspec/changes/<name>/proposal.md`
|
||||
- `openspec/changes/<name>/design.md`
|
||||
- `openspec/changes/<name>/tasks.md`
|
||||
- etc.
|
||||
|
||||
2. **Reference them naturally in conversation**
|
||||
- "Your design mentions using Redis, but we just realized SQLite fits better..."
|
||||
- "The proposal scopes this to premium users, but we're now thinking everyone..."
|
||||
|
||||
3. **Offer to capture when decisions are made**
|
||||
|
||||
| Insight Type | Where to Capture |
|
||||
|----------------------------|--------------------------------|
|
||||
| New requirement discovered | `specs/<capability>/spec.md` |
|
||||
| Requirement changed | `specs/<capability>/spec.md` |
|
||||
| Design decision made | `design.md` |
|
||||
| Scope changed | `proposal.md` |
|
||||
| New work identified | `tasks.md` |
|
||||
| Assumption invalidated | Relevant artifact |
|
||||
|
||||
Example offers:
|
||||
- "That's a design decision. Capture it in design.md?"
|
||||
- "This is a new requirement. Add it to specs?"
|
||||
- "This changes scope. Update the proposal?"
|
||||
|
||||
4. **The user decides** - Offer and move on. Don't pressure. Don't auto-capture.
|
||||
|
||||
---
|
||||
|
||||
## What You Don't Have To Do
|
||||
|
||||
- Follow a script
|
||||
- Ask the same questions every time
|
||||
- Produce a specific artifact
|
||||
- Reach a conclusion
|
||||
- Stay on topic if a tangent is valuable
|
||||
- Be brief (this is thinking time)
|
||||
|
||||
---
|
||||
|
||||
## Ending Discovery
|
||||
|
||||
There's no required ending. Discovery might:
|
||||
|
||||
- **Flow into a proposal**: "Ready to start? I can create a change proposal."
|
||||
- **Result in artifact updates**: "Updated design.md with these decisions"
|
||||
- **Just provide clarity**: User has what they need, moves on
|
||||
- **Continue later**: "We can pick this up anytime"
|
||||
|
||||
When things crystallize, you might offer a summary - but it's optional. Sometimes the thinking IS the value.
|
||||
|
||||
---
|
||||
|
||||
## Guardrails
|
||||
|
||||
- **Don't implement** - Never write code or implement features. Creating OpenSpec artifacts is fine, writing application code is not.
|
||||
- **Don't fake understanding** - If something is unclear, dig deeper
|
||||
- **Don't rush** - Discovery is thinking time, not task time
|
||||
- **Don't force structure** - Let patterns emerge naturally
|
||||
- **Don't auto-capture** - Offer to save insights, don't just do it
|
||||
- **Do visualize** - A good diagram is worth many paragraphs
|
||||
- **Do explore the codebase** - Ground discussions in reality
|
||||
- **Do question assumptions** - Including the user's and your own
|
||||
110
.agents/skills/source-command-opsx-propose/SKILL.md
Normal file
@@ -0,0 +1,110 @@
|
||||
---
|
||||
name: "source-command-opsx-propose"
|
||||
description: "Propose a new change - create it and generate all artifacts in one step"
|
||||
---
|
||||
|
||||
# source-command-opsx-propose
|
||||
|
||||
Use this skill when the user asks to run the migrated source command `opsx-propose`.
|
||||
|
||||
## Command Template
|
||||
|
||||
Propose a new change - create the change and generate all artifacts in one step.
|
||||
|
||||
I'll create a change with artifacts:
|
||||
- proposal.md (what & why)
|
||||
- design.md (how)
|
||||
- tasks.md (implementation steps)
|
||||
|
||||
When ready to implement, run /opsx:apply
|
||||
|
||||
---
|
||||
|
||||
**Input**: The argument after `/opsx:propose` is the change name (kebab-case), OR a description of what the user wants to build.
|
||||
|
||||
**Steps**
|
||||
|
||||
1. **If no input provided, ask what they want to build**
|
||||
|
||||
Use the **AskUserQuestion tool** (open-ended, no preset options) to ask:
|
||||
> "What change do you want to work on? Describe what you want to build or fix."
|
||||
|
||||
From their description, derive a kebab-case name (e.g., "add user authentication" → `add-user-auth`).
|
||||
|
||||
**IMPORTANT**: Do NOT proceed without understanding what the user wants to build.
|
||||
|
||||
2. **Create the change directory**
|
||||
```bash
|
||||
openspec new change "<name>"
|
||||
```
|
||||
This creates a scaffolded change at `openspec/changes/<name>/` with `.openspec.yaml`.
|
||||
|
||||
3. **Get the artifact build order**
|
||||
```bash
|
||||
openspec status --change "<name>" --json
|
||||
```
|
||||
Parse the JSON to get:
|
||||
- `applyRequires`: array of artifact IDs needed before implementation (e.g., `["tasks"]`)
|
||||
- `artifacts`: list of all artifacts with their status and dependencies
|
||||
|
||||
4. **Create artifacts in sequence until apply-ready**
|
||||
|
||||
Use the **TodoWrite tool** to track progress through the artifacts.
|
||||
|
||||
Loop through artifacts in dependency order (artifacts with no pending dependencies first):
|
||||
|
||||
a. **For each artifact that is `ready` (dependencies satisfied)**:
|
||||
- Get instructions:
|
||||
```bash
|
||||
openspec instructions <artifact-id> --change "<name>" --json
|
||||
```
|
||||
- The instructions JSON includes:
|
||||
- `context`: Project background (constraints for you - do NOT include in output)
|
||||
- `rules`: Artifact-specific rules (constraints for you - do NOT include in output)
|
||||
- `template`: The structure to use for your output file
|
||||
- `instruction`: Schema-specific guidance for this artifact type
|
||||
- `outputPath`: Where to write the artifact
|
||||
- `dependencies`: Completed artifacts to read for context
|
||||
- Read any completed dependency files for context
|
||||
- Create the artifact file using `template` as the structure
|
||||
- Apply `context` and `rules` as constraints - but do NOT copy them into the file
|
||||
- Show brief progress: "Created <artifact-id>"
|
||||
|
||||
b. **Continue until all `applyRequires` artifacts are complete**
|
||||
- After creating each artifact, re-run `openspec status --change "<name>" --json`
|
||||
- Check if every artifact ID in `applyRequires` has `status: "done"` in the artifacts array
|
||||
- Stop when all `applyRequires` artifacts are done
|
||||
|
||||
c. **If an artifact requires user input** (unclear context):
|
||||
- Use **AskUserQuestion tool** to clarify
|
||||
- Then continue with creation
|
||||
|
||||
5. **Show final status**
|
||||
```bash
|
||||
openspec status --change "<name>"
|
||||
```
|
||||
|
||||
**Output**
|
||||
|
||||
After completing all artifacts, summarize:
|
||||
- Change name and location
|
||||
- List of artifacts created with brief descriptions
|
||||
- What's ready: "All artifacts created! Ready for implementation."
|
||||
- Prompt: "Run `/opsx:apply` to start implementing."
|
||||
|
||||
**Artifact Creation Guidelines**
|
||||
|
||||
- Follow the `instruction` field from `openspec instructions` for each artifact type
|
||||
- The schema defines what each artifact should contain - follow it
|
||||
- Read dependency artifacts for context before creating new ones
|
||||
- Use `template` as the structure for your output file - fill in its sections
|
||||
- **IMPORTANT**: `context` and `rules` are constraints for YOU, not content for the file
|
||||
- Do NOT copy `<context>`, `<rules>`, `<project_context>` blocks into the artifact
|
||||
- These guide what you write, but should never appear in the output
|
||||
|
||||
**Guardrails**
|
||||
- Create ALL artifacts needed for implementation (as defined by schema's `apply.requires`)
|
||||
- Always read dependency artifacts before creating a new one
|
||||
- If context is critically unclear, ask the user - but prefer making reasonable decisions to keep momentum
|
||||
- If a change with that name already exists, ask if user wants to continue it or create a new one
|
||||
- Verify each artifact file exists after writing before proceeding to next
|
||||
132
.gitattributes
vendored
@@ -1 +1,131 @@
|
||||
*.blend filter=lfs diff=lfs merge=lfs -text
|
||||
# Define macros (only works in top-level gitattributes files)
|
||||
[attr]lfs filter=lfs diff=lfs merge=lfs -text
|
||||
|
||||
# 3D models
|
||||
*.collada lfs
|
||||
*.dae lfs
|
||||
*.dxf lfs
|
||||
*.FBX lfs
|
||||
*.fbx lfs
|
||||
*.jas lfs
|
||||
*.lws lfs
|
||||
*.lxo lfs
|
||||
*.obj lfs
|
||||
*.ply lfs
|
||||
*.skp lfs
|
||||
*.stl lfs
|
||||
*.stp lfs
|
||||
*.usd lfs
|
||||
*.usda lfs
|
||||
*.usdc lfs
|
||||
*.usdz lfs
|
||||
*.glb lfs
|
||||
*.gltf lfs
|
||||
|
||||
# Audio
|
||||
*.aif lfs
|
||||
*.aiff lfs
|
||||
*.it lfs
|
||||
*.mod lfs
|
||||
*.mp3 lfs
|
||||
*.ogg lfs
|
||||
*.s3m lfs
|
||||
*.wav lfs
|
||||
*.xm lfs
|
||||
|
||||
# Video
|
||||
*.asf lfs
|
||||
*.avi lfs
|
||||
*.flv lfs
|
||||
*.mov lfs
|
||||
*.mp4 lfs
|
||||
*.mpeg lfs
|
||||
*.mpg lfs
|
||||
*.ogv lfs
|
||||
*.wmv lfs
|
||||
*.mkv lfs
|
||||
|
||||
# Images
|
||||
*.bmp lfs
|
||||
*.exr lfs
|
||||
*.gif lfs
|
||||
*.hdr lfs
|
||||
*.iff lfs
|
||||
*.jpeg lfs
|
||||
*.jpg lfs
|
||||
*.pict lfs
|
||||
*.png lfs
|
||||
*.psd lfs
|
||||
*.tga lfs
|
||||
*.tif lfs
|
||||
*.tiff lfs
|
||||
*.webp lfs
|
||||
|
||||
# Compressed Archive
|
||||
*.7z lfs
|
||||
*.bz2 lfs
|
||||
*.gz lfs
|
||||
*.rar lfs
|
||||
*.tar lfs
|
||||
*.zip lfs
|
||||
|
||||
# Compiled Dynamic Library
|
||||
*.dll lfs
|
||||
*.pdb lfs
|
||||
*.so lfs
|
||||
|
||||
# Fonts
|
||||
*.otf lfs
|
||||
*.ttf lfs
|
||||
*.woff lfs
|
||||
*.woff2 lfs
|
||||
|
||||
# Executable/Installer
|
||||
*.apk lfs
|
||||
*.exe lfs
|
||||
|
||||
# Documents
|
||||
*.pdf lfs
|
||||
*.doc lfs
|
||||
*.xls lfs
|
||||
*.ppt lfs
|
||||
*.docx lfs
|
||||
*.xlsx lfs
|
||||
*.pptx lfs
|
||||
|
||||
# Adobe
|
||||
*.psd lfs
|
||||
*.ai lfs
|
||||
*.aep lfs
|
||||
*.prproj lfs
|
||||
*.spp lfs
|
||||
|
||||
# Zbrush
|
||||
*.zbr lfs
|
||||
*.zpr lfs
|
||||
*.ztl lfs
|
||||
*.c4d lfs
|
||||
|
||||
# Autodesk
|
||||
*.max lfs
|
||||
*.ma lfs
|
||||
*.mb lfs
|
||||
*.3dm lfs
|
||||
*.3ds lfs
|
||||
|
||||
# Blender
|
||||
*.blend lfs
|
||||
*.blend1 lfs
|
||||
*.c4d lfs
|
||||
|
||||
# Imaging
|
||||
*.dicom lfs
|
||||
*.dcm lfs
|
||||
*.nii lfs
|
||||
*.ome lfs
|
||||
*.map lfs
|
||||
*.mrc lfs
|
||||
|
||||
# Others
|
||||
*.abr lfs
|
||||
*.tpl lfs
|
||||
18
.github/workflows/release.yml
vendored
@@ -3,6 +3,7 @@ name: Release Version
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
# Publish on any tag starting with a `v`, e.g., v0.1.0
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
@@ -42,14 +43,17 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
lfs: "true"
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: 3.11
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v7
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
uv python install 3.11
|
||||
uv python pin 3.11
|
||||
uv sync
|
||||
- name: Build Extension
|
||||
run: | # build.py need tomlkit to edit blender_manifest.toml
|
||||
pip install tomlkit
|
||||
python build.py ${{ matrix.platform }}
|
||||
uv run build.py ${{ matrix.platform }} 3.11
|
||||
uv run build.py ${{ matrix.platform }} 3.13
|
||||
cd src/bioxelnodes
|
||||
zip -r ../../package.zip .
|
||||
- name: Upload Extension
|
||||
@@ -60,5 +64,5 @@ jobs:
|
||||
with:
|
||||
upload_url: ${{ needs.draft_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
|
||||
asset_path: ./package.zip
|
||||
asset_name: BioxelNodes_${{ needs.draft_release.outputs.version }}_${{ matrix.platform }}.zip
|
||||
asset_name: BioxelNodes.${{ needs.draft_release.outputs.version }}.${{ matrix.platform }}.zip
|
||||
asset_content_type: application/zip
|
||||
|
||||
300
.gitignore
vendored
@@ -1,6 +1,51 @@
|
||||
# Tempary files
|
||||
temp
|
||||
sandbox.*
|
||||
/notes/
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.envrc
|
||||
.venv
|
||||
.env.*
|
||||
!.env.example
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
.secrets
|
||||
.secrets.*
|
||||
!.secrets.example
|
||||
secrets/
|
||||
SECRETS/
|
||||
secrets.bak/
|
||||
|
||||
# Claude Code
|
||||
.claude/settings.local.json
|
||||
.claudian
|
||||
|
||||
# Obsidian
|
||||
.obsidian/*
|
||||
!.obsidian/snippets
|
||||
!.obsidian/app.json
|
||||
|
||||
*.canvas
|
||||
|
||||
# Keep odox for extract to openwiki
|
||||
!.obsidian/plugins
|
||||
.obsidian/plugins/*
|
||||
!.obsidian/plugins/odox
|
||||
|
||||
# Blender
|
||||
*.blend1
|
||||
blender_assets.cats.txt~
|
||||
blendcache_*
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*.py[codz]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
@@ -20,7 +65,6 @@ parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
pip-wheel-metadata/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
@@ -28,8 +72,8 @@ share/python-wheels/
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
@@ -47,8 +91,10 @@ htmlcov/
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py.cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
@@ -71,6 +117,7 @@ instance/
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
@@ -81,30 +128,70 @@ profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
# For a library or package, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# .python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
# Pipfile.lock
|
||||
|
||||
# celery beat schedule file
|
||||
# UV
|
||||
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
# uv.lock
|
||||
|
||||
# poetry
|
||||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||
# poetry.lock
|
||||
# poetry.toml
|
||||
|
||||
# pdm
|
||||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
||||
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
||||
# pdm.lock
|
||||
# pdm.toml
|
||||
.pdm-python
|
||||
.pdm-build/
|
||||
|
||||
# pixi
|
||||
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
||||
# pixi.lock
|
||||
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
||||
# in the .venv directory. It is recommended not to include this directory in version control.
|
||||
.pixi
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# Redis
|
||||
*.rdb
|
||||
*.aof
|
||||
*.pid
|
||||
|
||||
# RabbitMQ
|
||||
mnesia/
|
||||
rabbitmq/
|
||||
rabbitmq-data/
|
||||
|
||||
# ActiveMQ
|
||||
activemq-data/
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
@@ -123,16 +210,183 @@ dmypy.json
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
pythonlib*
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
*.blend1
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
blendcache_*
|
||||
# PyCharm
|
||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
# .idea/
|
||||
|
||||
*.ipynb
|
||||
# Abstra
|
||||
# Abstra is an AI-powered process automation framework.
|
||||
# Ignore directories containing user credentials, local state, and settings.
|
||||
# Learn more at https://abstra.io/docs
|
||||
.abstra/
|
||||
|
||||
.secrets
|
||||
# Visual Studio Code
|
||||
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
||||
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
||||
# you could uncomment the following to ignore the entire vscode folder
|
||||
# .vscode/
|
||||
|
||||
.vdb
|
||||
# Ruff stuff:
|
||||
.ruff_cache/
|
||||
|
||||
!scipy_ndimage/*/**
|
||||
# PyPI configuration file
|
||||
.pypirc
|
||||
|
||||
# Marimo
|
||||
marimo/_static/
|
||||
marimo/_lsp/
|
||||
__marimo__/
|
||||
|
||||
# Streamlit
|
||||
.streamlit/secrets.toml
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
.stylelintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
.output
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# vuepress v2.x temp and cache directory
|
||||
.temp
|
||||
.cache
|
||||
|
||||
# Sveltekit cache directory
|
||||
.svelte-kit/
|
||||
|
||||
# vitepress build output
|
||||
**/.vitepress/dist
|
||||
|
||||
# vitepress cache directory
|
||||
**/.vitepress/cache
|
||||
|
||||
# Docusaurus cache and generated files
|
||||
.docusaurus
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# Firebase cache directory
|
||||
.firebase/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# pnpm
|
||||
.pnpm-store
|
||||
|
||||
# yarn v3
|
||||
.pnp.*
|
||||
.yarn/*
|
||||
!.yarn/patches
|
||||
!.yarn/plugins
|
||||
!.yarn/releases
|
||||
!.yarn/sdks
|
||||
!.yarn/versions
|
||||
|
||||
# Vite files
|
||||
vite.config.js.timestamp-*
|
||||
vite.config.ts.timestamp-*
|
||||
.vite/
|
||||
22
.obsidian/app.json
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"showInlineTitle": false,
|
||||
"useMarkdownLinks": true,
|
||||
"pdfExportSettings": {
|
||||
"pageSize": "Letter",
|
||||
"landscape": false,
|
||||
"margin": "0",
|
||||
"downscalePercent": 100
|
||||
},
|
||||
"userIgnoreFilters": [
|
||||
"notes/assets/"
|
||||
],
|
||||
"showUnsupportedFiles": false,
|
||||
"attachmentFolderPath": "notes/assets",
|
||||
"livePreview": true,
|
||||
"showIndentGuide": false,
|
||||
"alwaysUpdateLinks": true,
|
||||
"openBehavior": "file:README",
|
||||
"newFileLocation": "folder",
|
||||
"newFileFolderPath": "notes",
|
||||
"newLinkFormat": "relative"
|
||||
}
|
||||
30
.obsidian/snippets/omoolab.css
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
/* not show label in canvas */
|
||||
.canvas-node-label {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.canvas-node-container:hover + .canvas-node-label {
|
||||
display: inherit;
|
||||
}
|
||||
|
||||
/* image caption */
|
||||
.image-embed {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.image-embed[alt]:after {
|
||||
content: attr(alt);
|
||||
display: block;
|
||||
padding-bottom: 12px;
|
||||
line-height: 2.0;
|
||||
font-style: italic;
|
||||
color: var(--text-faint);
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
|
||||
/* fix image in canvas */
|
||||
.image-embed {
|
||||
padding: 0;
|
||||
}
|
||||
1
.python-version
Normal file
@@ -0,0 +1 @@
|
||||
3.11
|
||||
92
AGENTS.md
Normal file
@@ -0,0 +1,92 @@
|
||||
# Bioxel Nodes
|
||||
|
||||
## 项目概览
|
||||
|
||||
Bioxel Nodes 是一个基于 Blender 的科学体数据可视化插件,利用 Blender 自带的 Geometry Nodes 与 Cycles(同时支持 EEVEE NEXT)处理并渲染体数据。
|
||||
|
||||
- 支持格式:`.dcm`、`.tif`/`.tiff`、`.nii`/`.nii.gz`、`.nrrd`、`.ome.tiff`、`.mrc`、`.h5` 等,完整列表见 `src/bioxelnodes/bioxel/data.py` 的 `SUPPORT_EXTS`
|
||||
- 支持 4D 体数据(多帧 / 多通道 / 时间序列)
|
||||
- v2.0.x 仅支持 Blender 5.0+
|
||||
- 核心依赖:SimpleITK、pyometiff、mrcfile、h5py、numpy、scipy、transforms3d、matplotlib
|
||||
|
||||
## 构建、测试与开发命令
|
||||
|
||||
- 环境:Python 3.11,依赖由 uv 管理(`uv.lock`)
|
||||
- `uv sync` 安装 / 同步依赖
|
||||
- `uv run pytest` 运行测试(当前暂无测试用例)
|
||||
- `uv run mkdocs serve` 本地预览文档;`uv run mkdocs build` 构建到 `site/`
|
||||
- `uv run mike deploy <version> -p` 发布版本化文档
|
||||
- `uv run build.py <platform> 3.11` 下载第三方 wheel 并更新 `src/bioxelnodes/blender_manifest.toml`,`platform` 取 `windows-x64` / `linux-x64` / `macos-arm64` / `macos-x64`
|
||||
- `python pack.py <platform> [output.zip]` 将 `src/bioxelnodes` 打包为 zip
|
||||
- 发布:推送 `v*` 标签触发 `.github/workflows/release.yml`,产物命名 `BioxelNodes.<version>.<platform>.zip`
|
||||
|
||||
## 架构
|
||||
|
||||
```text
|
||||
src/bioxelnodes/ 插件包根目录
|
||||
├── __init__.py 入口:register/unregister、CLI 命令与 WindowManager 属性
|
||||
├── auto_load.py 自动发现并按拓扑排序注册 bpy 类
|
||||
├── constants.py 常量(节点库路径等)
|
||||
├── preferences.py AddonPreferences(缓存目录)
|
||||
├── props.py PropertyGroup / UIList / 属性更新回调
|
||||
├── menus.py 菜单与右键菜单
|
||||
├── panels.py 面板
|
||||
├── asset_library.py "O Bioxel" 资产库管理
|
||||
├── node.py 节点组加载与添加
|
||||
├── layer.py VDB 缓存、快照、图层元数据(text datablock JSON)
|
||||
├── utils.py 通用工具(进度、对象查找、驱动等)
|
||||
├── exceptions.py 向后兼容占位(自定义异常已改用内置异常)
|
||||
├── blender_manifest.toml Blender 扩展清单
|
||||
├── assets/O_Bioxel/ 节点库 .blend 与资产目录
|
||||
├── wheels/ 随扩展分发的第三方 wheel
|
||||
├── bioxel/ 核心数据模型(不依赖 Blender)
|
||||
│ ├── data.py Data 类与解析(read / read_meta)
|
||||
│ ├── parse.py 解析函数(parse_volumetric_data 等)
|
||||
│ ├── layer.py Layer:TXYZC 顺序 ndarray + affine 变换
|
||||
│ ├── container.py Container:name + layers
|
||||
│ └── io.py HDF5 读写 Container
|
||||
└── operators/ Operator 实现
|
||||
├── io.py 导入 / 导出算子,启动后台导入进程
|
||||
├── io_worker.py 后台 CLI 导入 worker(bioxelnodes_import_worker)
|
||||
├── layer.py 图层管理算子
|
||||
├── node.py AddNode
|
||||
├── structure.py ExtractMesh
|
||||
└── misc.py 杂项算子
|
||||
```
|
||||
|
||||
数据流:导入时主进程通过 `operators/io.py` 启动一个后台 Blender 子进程(`blender --background --command bioxelnodes_import_worker`),由 `io_worker.py` 解析数据、生成 `Layer`,写为 VDB 缓存,并通过 JSON 文件(`progress.json` / `result.json` / `cancel`)回传进度与结果,避免阻塞 UI。
|
||||
|
||||
仓库根目录另有 `docs/`(mkdocs-material 文档,中英双语)、`openspec/`(spec-driven 变更流程)、`.agents/`(技能定义)。
|
||||
|
||||
## 总规范
|
||||
|
||||
- 说明性内容(例如提交说明、文档、注释、mermaid),以中文为主,专有名词、约定俗称可用英文
|
||||
|
||||
## Markdown 规范
|
||||
|
||||
- 不使用`---`分割器
|
||||
- `# Heading` 一级标题仅用于开头
|
||||
- mermaid 节点名用英文字符
|
||||
|
||||
## 代码规范
|
||||
|
||||
- 避免嵌套结构
|
||||
- 特殊的、非常规的需要写注释
|
||||
- 变量、函数名、Docstring 用全英文
|
||||
- 同一事物用统一表达
|
||||
- 使用的依赖越少越好
|
||||
- 选用简单直接的方式实现
|
||||
- 代码、执行方式改变,调整已有的文档、计划,而非新建
|
||||
|
||||
## Shell 规范
|
||||
|
||||
- 优先使用、提供 Git Bash 执行所有 Shell 命令
|
||||
- Windows 路径在 Bash 命令中优先使用正斜杠形式
|
||||
|
||||
## Blender 开发规范
|
||||
|
||||
- 插件、资产库压缩包名用大驼峰,如果需要,用`b45`来表示适用blender版本。比如`OmooLab.v0.1.0.b45.zip`
|
||||
- Operator、Menu、Panel、AddonPreferences... Class 用大驼峰命名,不加任何前缀。Operator 动宾结构,比如`RenderImage`。Menu、Panel 以它们本身为后缀,比如`RenderPanel`
|
||||
- 根据项目名提炼项目缩写,作为 bl_idname 和 自定义 Property 的前缀以区分其他功能和属性,以`Omoo`为例
|
||||
- bl_idname 用下划线小写命名,Operator 的 bl_idname 以`omoo.*`为前缀,比如`omoo.render_panel`;Menu 的以`OMOO_MT_*`为前缀;Panel 的以`OMOO_PT_*`为前缀。比如`OMOO_PT_render_panel`
|
||||
- 自定义 Property 用下划线小写命名,以`omoo_*`为前缀。比如`omoo_progress_factor`
|
||||
11
README.md
@@ -1,4 +1,6 @@
|
||||
[中文文档](https://uj6xfhbzp0.feishu.cn/wiki/LPKEwjooSivxjskWHlCcQznjnNf?from=from_copylink)
|
||||
**v2.0.x has been released, supporting only Blender 5.0+. The usage is completely different from before and is not compatible with old version files. See http://docs.omoolab.xyz/bioxelnodes/2.0.x/en/basics/**
|
||||
|
||||
[中文文档](https://docs.omoolab.xyz/bioxelnodes/latest/)
|
||||
|
||||
# Bioxel Nodes
|
||||
|
||||
@@ -26,7 +28,7 @@ Bioxel Nodes is a Blender addon for scientific volumetric data visualization. It
|
||||
| :--------------------------------------------------------------------: | :---------------------------------------------------------------------: |
|
||||
| Support 4D volumetric data | Real-time render with eevee |
|
||||
|
||||
**Read the [getting started](https://omoolab.github.io/BioxelNodes/latest/installation) to begin your journey into visualizing volumetric data!**
|
||||
**Read the [getting started](https://docs.omoolab.xyz/bioxelnodes/latest/en/installation) to begin your journey into visualizing volumetric data!**
|
||||
|
||||
Welcome to our [discord server](https://discord.gg/pYkNyq2TjE), if you have any problems with this add-on.
|
||||
|
||||
@@ -36,11 +38,6 @@ If you want to cite this work, you can cite it from Zenodo:
|
||||
|
||||
[](https://zenodo.org/badge/latestdoi/786623459)
|
||||
|
||||
## Known Limitations
|
||||
|
||||
- Only one cutter supported in EEVEE render
|
||||
- Shader fail to work when convert to mesh.
|
||||
- Section surface cannot be generated when convert to mesh (will be supported soon)
|
||||
|
||||
## Roadmap
|
||||
|
||||
|
||||
40
build.py
@@ -12,12 +12,15 @@ class Platform:
|
||||
blender_tag: str
|
||||
|
||||
|
||||
required_packages = ["SimpleITK==2.3.1",
|
||||
required_packages = ["SimpleITK==2.5.5",
|
||||
"pyometiff==1.0.0",
|
||||
"mrcfile==1.5.1",
|
||||
"h5py==3.11.0",
|
||||
"h5py==3.14.0",
|
||||
"transforms3d==0.4.2",
|
||||
"tifffile==2024.7.24"]
|
||||
"tifffile==2024.7.24",
|
||||
"matplotlib==3.10.7",
|
||||
"pillow==11.2.1",
|
||||
"scipy==1.16.3"]
|
||||
|
||||
|
||||
platforms = {"windows-x64": Platform(pypi_suffix="win_amd64",
|
||||
@@ -31,7 +34,8 @@ platforms = {"windows-x64": Platform(pypi_suffix="win_amd64",
|
||||
|
||||
packages_to_remove = {
|
||||
"imagecodecs",
|
||||
"numpy"
|
||||
"numpy",
|
||||
"packaging"
|
||||
}
|
||||
|
||||
|
||||
@@ -40,36 +44,33 @@ def run_python(args: str):
|
||||
subprocess.run([python] + args.split(" "))
|
||||
|
||||
|
||||
def build_extension(platform: Platform, python_version="3.11") -> None:
|
||||
def build_extension(platform: Platform, python_version: str) -> None:
|
||||
wheel_dirpath = Path("./src/bioxelnodes/wheels")
|
||||
toml_filepath = Path("./src/bioxelnodes/blender_manifest.toml")
|
||||
scipy_ndimage_dirpath = Path("./scipy_ndimage", platform.blender_tag)
|
||||
|
||||
# download required_packages
|
||||
run_python(
|
||||
f"-m pip download {' '.join(required_packages)} --dest {wheel_dirpath.as_posix()} --only-binary=:all: --python-version={python_version} --platform={platform.pypi_suffix}"
|
||||
)
|
||||
|
||||
for f in wheel_dirpath.glob('*.whl'):
|
||||
for f in wheel_dirpath.glob("*.whl"):
|
||||
if any([package in f.name for package in packages_to_remove]):
|
||||
f.unlink(missing_ok=True)
|
||||
|
||||
elif platform.blender_tag == "macos-arm64" and \
|
||||
"lxml" in f.name and "universal2" in f.name:
|
||||
f.rename(Path(f.parent,
|
||||
f.name.replace("universal2", "arm64")))
|
||||
|
||||
for ndimage_filepath in scipy_ndimage_dirpath.iterdir():
|
||||
to_filepath = Path("./src/bioxelnodes/bioxel/scipy", ndimage_filepath.name)
|
||||
shutil.copy(ndimage_filepath, to_filepath)
|
||||
|
||||
elif (
|
||||
platform.blender_tag == "macos-arm64"
|
||||
and "lxml" in f.name
|
||||
and "universal2" in f.name
|
||||
):
|
||||
f.rename(Path(f.parent, f.name.replace("universal2", "arm64")))
|
||||
|
||||
# Load the TOML file
|
||||
with toml_filepath.open("r") as file:
|
||||
manifest = tomlkit.parse(file.read())
|
||||
|
||||
manifest["platforms"] = [platform.blender_tag]
|
||||
manifest["wheels"] = [f"./wheels/{f.name}"
|
||||
for f in wheel_dirpath.glob('*.whl')]
|
||||
manifest["wheels"] = [
|
||||
f"./wheels/{f.name}" for f in wheel_dirpath.glob("*.whl")]
|
||||
|
||||
# build.append('generated', generated)
|
||||
# manifest.append('build', build)
|
||||
@@ -82,8 +83,9 @@ def build_extension(platform: Platform, python_version="3.11") -> None:
|
||||
|
||||
def main():
|
||||
platform_name = sys.argv[1]
|
||||
python_version = sys.argv[2] or "3.11"
|
||||
platform = platforms[platform_name]
|
||||
build_extension(platform)
|
||||
build_extension(platform, python_version)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
99
docs/SARS-Cov-2.en.md
Normal file
@@ -0,0 +1,99 @@
|
||||
# SARS-Cov-2
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
In this tutorial, we'll make a structural visualzation of the SARS-Cov-2 Virus. Please see [step by step](step_by_step.md) to make sure you have a basic understanding of how to use the addon, and make sure the addon version is v1.0.2 or higher!
|
||||
|
||||
Research data is from paper published in September 2020 in Cell Press ([https://www.cell.com/cell/fulltext/S0092-8674(20)31159-4](<https://www.cell.com/cell/fulltext/S0092-8674(20)31159-4>)) by Li Sai team at Tsinghua University. This research revealed the molecular assembly of the authentic SARS-CoV-2 virus using cryoelectron tomography (cryo-ET) and subtomogram averaging (STA). Here is an official video of this study
|
||||
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/JSKl5VY4k5w?si=t4LhrCRebxrX_Saf&controls=0" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
|
||||
|
||||
"It remains enigmatic how coronaviruses pack the ∼30-kb RNA into the ∼80-nm-diameter viral lumen. Are the RNPs ordered relative to each other to avoid RNA entangling, knotting, or even damage or are they involved in virus assembly?" Three assembly classes were proposed in the paper, we will make a visualzation of the "eggs-in-a-nest"-shaped RNPs assembly, based on real cryo-ET data.
|
||||
|
||||
## Download and import data
|
||||
|
||||
The data of this research is hosted on EMDB ([https://www.ebi.ac.uk/emdb](https://www.ebi.ac.uk/emdb)), and the website of SARS-Cov-2 virus is [here](https://www.ebi.ac.uk/emdb/EMD-30430). Open the page, find "Download" button and select the first selection "3D Volume (.map.gz)".
|
||||
|
||||
In case you can't download data, you can download here.
|
||||
|
||||
[SARS-Cov-2.map](https://drive.google.com/file/d/1LMybsmTVbwQ38_eqAx6hbZTc5p2fdcjK/view?usp=sharing)
|
||||
|
||||
After downloading, put it into any directory and import the data. In the import options, it is recommended to adjust the Bioxel Size to 5, in order to reduce the shape of the data to increase the speed of calculation and rendering. If you are confident in the performance of your hardware, you can leave the original 2.72 unchanged. After adjusting the Bioxel Size, the shape of the converted data will be calculated below based on the current bioxel size. The amount of data will increase exponentially with larger shape, and may result in OOM (out of memory).
|
||||
|
||||
## Cutout the Virus
|
||||
|
||||
After importing, you can get the virus by creating and connecting nodes and setting parameters as shown below
|
||||
|
||||

|
||||
|
||||
Place the light and the camera in the way as below. The backlight is a area light, color white, intensity 500W, spread 90°, and inside the virus, place a point light, color `FFD08D`, intensity 5W. Camera focal length is 200 mm. the background color is pure black. The Look of the color management is High Contrast.
|
||||
|
||||

|
||||
|
||||
Continue editing the node, followed by "Set Properies" and "Set Color by Ramp 4" node, the parameters of these two nodes are set as shown in the figure, where the color part, from top to bottom, is set to `E1D0FC` (1.0), `FFE42D` (0.5), `3793FF` (0.5), `FFFF8EC` (0.1) (alpha value in parentheses). Color alpha also affects density.
|
||||
|
||||

|
||||
|
||||
If you feel that rendering is too slow, see [here](improve_performance.md) for suggestions
|
||||
|
||||
## Color the RNPs alone
|
||||
|
||||
The current rendering is pretty good, but considering that my goal is to make it clear how the RNPs are arranged within the virus, the RNPs should be colored differently than the others. So how to color the RNPs alone?
|
||||
|
||||
First of all, we have to separate the RNPs. The value of RNPs is between the membrane and S protein, so it is very difficult to separate. The good thing is that the virus is spherical, we can separate the RNPs part of the virus from the rest by using a sphere cutter. To do so, in the Geometry Nodes panel menu of the container, click **Bioxel Nodes > Add a Cutter > Sphere Cutter**, and adjust the scale and position of the newly created sphere object named "Sphere_Cutter" appropriately, so that it can just separate the internal RNPs and membrane of the virus.
|
||||
|
||||

|
||||
|
||||
The process of changing the position of the "Sphere_Cutter" object can be very laggy, then you can turn off "With Surface" and do it in Slice Viewer mode. Once you are happy with it, you can restore the settings.
|
||||
|
||||
Then we turn on Invert in the "Sphere Cutter" node and you can see the opposite result. This way we've managed to separate the two, next let's color them separately and finally merge them with Join Component. Create and join the nodes as shown below, where the second Cutter node is copied and the color value in Set Color is `FFDDFE` (0.5). If all is well, the rendering should look like below.
|
||||
|
||||

|
||||
|
||||
At this point, the rendering of a SARS-Cov-2 virus is complete!
|
||||
|
||||
## Render RNPs and Membranes
|
||||
|
||||
Realistic rendering is great, but Non-photorealistic rendering (NPR) is better for presenting structural information. So I will render ultrastructure of the RNPs assembly with toon shader.
|
||||
|
||||

|
||||
|
||||
The silhouettes of RNPs uses Blender's Line Art feature, but Line Art must be based on a mesh. Select the nodes that are extruding the RNPs (i.e., the "Cut" nodes that are in charge of cutting out the RNPs), and right-click, click **Bioxel Nodes > Extract Mesh**. This gives you a new mesh object of the RNPs.
|
||||
|
||||
Extract the membrane mesh in the same way.
|
||||
|
||||
The membrane has a much higher value than the rest of the virus, so let's create a new "Cutout" node, also after the ReCenter, but with the threshold adjusted to 0.13. After the Cutout, connect to the "To Surface" node and parameterize it as shown in the figure, noting that the Remove Island Threshold is set to 1000 so that any fragments smaller than 1000 pts be eliminated. Then select the "To Surface" node, and perform the operation of extracting the mesh.
|
||||
|
||||

|
||||
|
||||
The mesh of the membrane needs to be cut in half, this can be done with the Box Trim brush in sculpt mode or with the Boolean modifier. the mesh of the RNPs may also need some repair work, I cleaned up some of the broken surfaces of the RNPs. all the meshes are now ready to be used.
|
||||
|
||||

|
||||
|
||||
For Line Art, please see the video tutorial from Blender Secrets.
|
||||
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/aIWdBq7-ias?si=CrcStx5VVJBwDpzu&controls=0" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
|
||||
|
||||
Finally, an infographic on the ultrastructure of RNPs is done!
|
||||
|
||||

|
||||
|
||||
If you have trouble following the docs, you can download the project files.
|
||||
|
||||
[SARS-Cov-2.zip](https://drive.google.com/file/d/15GpIoIjVAE-Jr98zWo7oupuk1KfRVPmk/view?usp=sharing)
|
||||
|
||||
## Homework
|
||||
|
||||
Other data relevant to the study are provided in the paper, you could try visualizing them.
|
||||
|
||||

|
||||
|
||||
Go to the official EMDB website https://www.ebi.ac.uk/emdb/ and enter the EMD number in the search box to get them.
|
||||
|
||||
The Electron Microscopy Data Bank (EMDB) is a public repository for cryogenic-sample Electron Microscopy (cryoEM) volumes and representative tomograms of macromolecular complexes and subcellular structures. If you want to get data on other virus, just enter their name in the search box. For example, hepatitis B virus, enter it into the search box, then select Virus in the Sample Type on the left side, and download the data you need (it is better to find the corresponding paper to clarify the data information).
|
||||
|
||||
**Try to visualize hepatitis B virus.**
|
||||
|
||||

|
||||
@@ -4,96 +4,96 @@
|
||||
|
||||

|
||||
|
||||
In this tutorial, we'll make a structural visualzation of the SARS-Cov-2 Virus. Please see [step by step](step_by_step.md) to make sure you have a basic understanding of how to use the addon, and make sure the addon version is v1.0.2 or higher!
|
||||
在本教程中,我们将制作 SARS-Cov-2 病毒的结构可视化。请确保您已阅读[分步指南](step_by_step.md)以了解插件的基本使用方法,并确保插件版本为 v1.0.2 或更高!
|
||||
|
||||
Research data is from paper published in September 2020 in Cell Press ([https://www.cell.com/cell/fulltext/S0092-8674(20)31159-4](<https://www.cell.com/cell/fulltext/S0092-8674(20)31159-4>)) by Li Sai team at Tsinghua University. This research revealed the molecular assembly of the authentic SARS-CoV-2 virus using cryoelectron tomography (cryo-ET) and subtomogram averaging (STA). Here is an official video of this study
|
||||
研究数据来自 2020 年 9 月发表在 Cell Press 的论文([https://www.cell.com/cell/fulltext/S0092-8674(20)31159-4](<https://www.cell.com/cell/fulltext/S0092-8674(20)31159-4>)),作者是清华大学李赛团队。该研究使用冷冻电子断层扫描(cryo-ET)和亚断层图平均(STA)揭示了真实 SARS-CoV-2 病毒的分子组装。以下是该研究的官方视频:
|
||||
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/JSKl5VY4k5w?si=t4LhrCRebxrX_Saf&controls=0" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
|
||||
|
||||
"It remains enigmatic how coronaviruses pack the ∼30-kb RNA into the ∼80-nm-diameter viral lumen. Are the RNPs ordered relative to each other to avoid RNA entangling, knotting, or even damage or are they involved in virus assembly?" Three assembly classes were proposed in the paper, we will make a visualzation of the "eggs-in-a-nest"-shaped RNPs assembly, based on real cryo-ET data.
|
||||
"冠状病毒如何将约 30kb 的 RNA 包装到约 80nm 直径的病毒腔内仍然是个谜。RNP 彼此之间是否有序以避免 RNA 缠结、打结或损坏,还是它们参与病毒组装?" 论文中提出了三类组装方式,我们将基于真实的冷冻电镜数据,制作"巢中蛋"形 RNP 组装的可视化。
|
||||
|
||||
## Download and import data
|
||||
## 下载和导入数据
|
||||
|
||||
The data of this research is hosted on EMDB ([https://www.ebi.ac.uk/emdb](https://www.ebi.ac.uk/emdb)), and the website of SARS-Cov-2 virus is [here](https://www.ebi.ac.uk/emdb/EMD-30430). Open the page, find "Download" button and select the first selection "3D Volume (.map.gz)".
|
||||
该研究的数据托管在 EMDB([https://www.ebi.ac.uk/emdb](https://www.ebi.ac.uk/emdb)),SARS-Cov-2 病毒网站是[这里](https://www.ebi.ac.uk/emdb/EMD-30430)。打开页面,找到"Download"按钮,选择第一个选项"3D Volume (.map.gz)"。
|
||||
|
||||
In case you can't download data, you can download here.
|
||||
如果您无法下载数据,可以从这里下载。
|
||||
|
||||
[SARS-Cov-2.map](https://drive.google.com/file/d/1LMybsmTVbwQ38_eqAx6hbZTc5p2fdcjK/view?usp=sharing)
|
||||
|
||||
After downloading, put it into any directory and import the data. In the import options, it is recommended to adjust the Bioxel Size to 5, in order to reduce the shape of the data to increase the speed of calculation and rendering. If you are confident in the performance of your hardware, you can leave the original 2.72 unchanged. After adjusting the Bioxel Size, the shape of the converted data will be calculated below based on the current bioxel size. The amount of data will increase exponentially with larger shape, and may result in OOM (out of memory).
|
||||
下载后,放到任意目录并导入数据。在导入选项中,建议将 Bioxel Size 调整为 5,以减小数据形状,提高计算和渲染速度。如果您对硬件性能有信心,可以保持原始的 2.72 不变。调整 Bioxel Size 后,下方会根据当前的 bioxel size 计算转换后数据的形状。数据量会随着形状增大呈指数增长,可能会导致内存不足(OOM)。
|
||||
|
||||
## Cutout the Virus
|
||||
## 切割病毒
|
||||
|
||||
After importing, you can get the virus by creating and connecting nodes and setting parameters as shown below
|
||||
导入后,您可以通过创建和连接节点并设置参数来获取病毒,如下图所示。
|
||||
|
||||

|
||||
|
||||
Place the light and the camera in the way as below. The backlight is a area light, color white, intensity 500W, spread 90°, and inside the virus, place a point light, color `FFD08D`, intensity 5W. Camera focal length is 200 mm. the background color is pure black. The Look of the color management is High Contrast.
|
||||
按下图所示放置灯光和相机。背光是区域光,白色,强度 500W,扩散 90°;在病毒内部放置一个点光源,颜色 `FFD08D`,强度 5W。相机焦距为 200mm。背景颜色为纯黑色。颜色管理的 Look 为 High Contrast。
|
||||
|
||||

|
||||
|
||||
Continue editing the node, followed by "Set Properies" and "Set Color by Ramp 4" node, the parameters of these two nodes are set as shown in the figure, where the color part, from top to bottom, is set to `E1D0FC` (1.0), `FFE42D` (0.5), `3793FF` (0.5), `FFFF8EC` (0.1) (alpha value in parentheses). Color alpha also affects density.
|
||||
继续编辑节点,接着是"Set Properties"和"Set Color by Ramp 4"节点,这两个节点的参数设置如下图,其中颜色部分,从上到下设置为 `E1D0FC`(1.0)、`FFE42D`(0.5)、`3793FF`(0.5)、`FFFF8EC`(0.1)(括号中为 alpha 值)。颜色的 alpha 值也会影响密度。
|
||||
|
||||

|
||||
|
||||
If you feel that rendering is too slow, see [here](improve_performance.md) for suggestions
|
||||
如果您觉得渲染太慢,请参阅[这里](improve_performance.md)获取建议。
|
||||
|
||||
## Color the RNPs alone
|
||||
## 单独为 RNP 着色
|
||||
|
||||
The current rendering is pretty good, but considering that my goal is to make it clear how the RNPs are arranged within the virus, the RNPs should be colored differently than the others. So how to color the RNPs alone?
|
||||
当前的渲染效果很好,但考虑到我的目标是让您清楚看到 RNP 在病毒内部的排列方式,RNP 应该与其他部分用不同颜色着色。那么如何单独为 RNP 着色呢?
|
||||
|
||||
First of all, we have to separate the RNPs. The value of RNPs is between the membrane and S protein, so it is very difficult to separate. The good thing is that the virus is spherical, we can separate the RNPs part of the virus from the rest by using a sphere cutter. To do so, in the Geometry Nodes panel menu of the container, click **Bioxel Nodes > Add a Cutter > Sphere Cutter**, and adjust the scale and position of the newly created sphere object named "Sphere_Cutter" appropriately, so that it can just separate the internal RNPs and membrane of the virus.
|
||||
首先,我们必须分离 RNP。RNP 的值介于膜和 S 蛋白之间,因此很难分离。好在病毒是球形的,我们可以使用球形切割器将病毒的 RNP 部分与其余部分分离。为此,在容器的几何节点面板菜单中,点击 **Bioxel Nodes > Add a Cutter > Sphere Cutter**,并适当调整新创建的名为"Sphere_Cutter"的球体对象的大小和位置,使其恰好能将病毒内部的 RNP 和膜分离。
|
||||
|
||||

|
||||
|
||||
The process of changing the position of the "Sphere_Cutter" object can be very laggy, then you can turn off "With Surface" and do it in Slice Viewer mode. Once you are happy with it, you can restore the settings.
|
||||
改变"Sphere_Cutter"对象的位置可能会非常卡顿,此时您可以关闭"With Surface"并在 Slice Viewer 模式下操作。满意后,恢复设置。
|
||||
|
||||
Then we turn on Invert in the "Sphere Cutter" node and you can see the opposite result. This way we've managed to separate the two, next let's color them separately and finally merge them with Join Component. Create and join the nodes as shown below, where the second Cutter node is copied and the color value in Set Color is `FFDDFE` (0.5). If all is well, the rendering should look like below.
|
||||
然后在"Sphere Cutter"节点中打开 Invert,您可以看到相反的结果。这样我们就成功将两者分离了。接下来让我们分别着色,最后用 Join Component 合并。按如下图所示创建和连接节点,其中第二个 Cutter 节点是复制的,Set Color 中的颜色值设置为 `FFDDFE`(0.5)。如果一切正常,渲染结果应该如下图所示。
|
||||
|
||||

|
||||
|
||||
At this point, the rendering of a SARS-Cov-2 virus is complete!
|
||||
此时,SARS-Cov-2 病毒的渲染完成了!
|
||||
|
||||
## Render RNPs and Membranes
|
||||
## 渲染 RNP 和膜
|
||||
|
||||
Realistic rendering is great, but Non-photorealistic rendering (NPR) is better for presenting structural information. So I will render ultrastructure of the RNPs assembly with toon shader.
|
||||
写实渲染很棒,但非写实渲染(NPR)在呈现结构信息方面更好。因此,我将使用卡通着色器来渲染 RNP 组装的首尾结构。
|
||||
|
||||

|
||||
|
||||
The silhouettes of RNPs uses Blender's Line Art feature, but Line Art must be based on a mesh. Select the nodes that are extruding the RNPs (i.e., the "Cut" nodes that are in charge of cutting out the RNPs), and right-click, click **Bioxel Nodes > Extract Mesh**. This gives you a new mesh object of the RNPs.
|
||||
RNP 的轮廓使用 Blender 的线稿(Line Art)功能,但线稿必须基于网格。选择挤出 RNP 的节点(即负责切割出 RNP 的"Cut"节点),右键点击 **Bioxel Nodes > Extract Mesh**。这将为您创建一个 RNP 的新网格对象。
|
||||
|
||||
Extract the membrane mesh in the same way.
|
||||
用同样的方式提取膜网格。
|
||||
|
||||
The membrane has a much higher value than the rest of the virus, so let's create a new "Cutout" node, also after the ReCenter, but with the threshold adjusted to 0.13. After the Cutout, connect to the "To Surface" node and parameterize it as shown in the figure, noting that the Remove Island Threshold is set to 1000 so that any fragments smaller than 1000 pts be eliminated. Then select the "To Surface" node, and perform the operation of extracting the mesh.
|
||||
膜的病毒值远高于其他部分,因此让我们创建一个新的"Cutout"节点,同样在 ReCenter 之后,但阈值调整为 0.13。Cutout 后,连接到"To Surface"节点并按如下图所示设置参数,注意 Remove Island Threshold 设置为 1000,以便消除小于 1000 pts 的任何碎片。然后选择"To Surface"节点,执行提取网格的操作。
|
||||
|
||||

|
||||
|
||||
The mesh of the membrane needs to be cut in half, this can be done with the Box Trim brush in sculpt mode or with the Boolean modifier. the mesh of the RNPs may also need some repair work, I cleaned up some of the broken surfaces of the RNPs. all the meshes are now ready to be used.
|
||||
膜的网格需要切成两半,这可以通过雕刻模式中的 Box Trim 笔刷或布尔修改器来完成。RNP 的网格也可能需要一些修复工作,我清理了一些 RNP 的破损表面。所有网格现在都可以使用了。
|
||||
|
||||

|
||||
|
||||
For Line Art, please see the video tutorial from Blender Secrets.
|
||||
关于线稿,请参阅 Blender Secrets 的视频教程。
|
||||
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/aIWdBq7-ias?si=CrcStx5VVJBwDpzu&controls=0" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
|
||||
|
||||
Finally, an infographic on the ultrastructure of RNPs is done!
|
||||
最后,RNP 超微结构的信息图完成了!
|
||||
|
||||

|
||||
|
||||
If you have trouble following the docs, you can download the project files.
|
||||
如果您按照文档有困难,可以下载项目文件。
|
||||
|
||||
[SARS-Cov-2.zip](https://drive.google.com/file/d/15GpIoIjVAE-Jr98zWo7oupuk1KfRVPmk/view?usp=sharing)
|
||||
|
||||
## Homework
|
||||
## 作业
|
||||
|
||||
Other data relevant to the study are provided in the paper, you could try visualizing them.
|
||||
论文中提供了其他相关数据,您可以尝试可视化它们。
|
||||
|
||||

|
||||
|
||||
Go to the official EMDB website https://www.ebi.ac.uk/emdb/ and enter the EMD number in the search box to get them.
|
||||
前往官方 EMDB 网站 https://www.ebi.ac.uk/emdb/,在搜索框中输入 EMD 编号即可获取。
|
||||
|
||||
The Electron Microscopy Data Bank (EMDB) is a public repository for cryogenic-sample Electron Microscopy (cryoEM) volumes and representative tomograms of macromolecular complexes and subcellular structures. If you want to get data on other virus, just enter their name in the search box. For example, hepatitis B virus, enter it into the search box, then select Virus in the Sample Type on the left side, and download the data you need (it is better to find the corresponding paper to clarify the data information).
|
||||
电子显微镜数据银行(EMDB)是一个公共仓库,用于存放冷冻样品的电子显微镜(cryoEM)体积和代表性断层图。如果您想获取其他病毒的数据,只需在搜索框中输入其名称即可。例如,乙型肝炎病毒,在搜索框中输入,然后选择左侧 Sample Type 中的 Virus,下载您需要的数据(最好找到相应的论文来明确数据信息)。
|
||||
|
||||
**Try to visualize hepatitis B virus.**
|
||||
**尝试可视化乙型肝炎病毒。**
|
||||
|
||||

|
||||

|
||||
46
docs/advanced.en.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# Advanced Usage
|
||||
|
||||
## Cut "Structure"
|
||||
|
||||
"Structure" can be cut to show partial structure, accomplished through the O Cut series nodes. For example, add the **O Cut to Region** node as shown below and connect it. Add any object from the scene as the "Region", and input it into the node:
|
||||
|
||||

|
||||
|
||||
By properly adjusting the position and rotation of the "Region" object, you can see that the skull structure is confined within the region.
|
||||
|
||||
!!! note
|
||||
The add-on provides a function to quickly make objects phantom. In 3D Viewport mode, right-click the "Region" object and select **Bioxel Nodes > Toggle Phantom** from the menu.
|
||||
|
||||
!!! warning
|
||||
Cutting increases computation and affects real-time performance. Check Resample on O Layer to improve performance.
|
||||
|
||||
**O Cut Small Parts** node is a cleanup tool that quickly removes scattered fragments and keeps only clean, continuous large structures. However, the computation is particularly time-consuming, so be aware of performance.
|
||||
|
||||

|
||||
|
||||
If you are familiar with geometry nodes, you can also directly define the cutting execution range through **O Cut Structure**. For example, in the image below, select the part where the cutting position X is greater than 0.
|
||||
|
||||

|
||||
|
||||
## Structure Property Settings
|
||||
|
||||
Expand the Properties of **O Cutout by Threshold**, where you can directly modify various property values, but they can only be set uniformly. We can use field-type data to assign differences. Take the color property as an example: for instance, connecting a Position node directly produces the effect shown below:
|
||||
|
||||

|
||||
|
||||
We can also map layer values to color gradients, which requires the **O Scalar Layer to Color** node (such conversion function nodes are all under Add > O Bioxel > Utilities in the node menu). Adjust as follows:
|
||||
|
||||
- **O Cutout by Threshold**: Set Threshold to 20
|
||||
- **O Scalar Layer to Color**: Set From Min and From Max to 20 and 90 respectively
|
||||
|
||||

|
||||
|
||||
Since soft tissue CT values are lower than bone tissue, when the threshold is lowered, you can see that in addition to the skull, the attached soft tissue is also presented. The From Min and From Max of **O Scalar Layer to Color** define the color mapping range from 0 to 1. Therefore, low-value soft tissue appears black, and high-value bone tissue appears white.
|
||||
|
||||
We can also customize the mapping method through the **Closure** node in Blender 5.0+. For example, connect a **Color Ramp** node to change the black area belonging to soft tissue to dark red:
|
||||
|
||||

|
||||
|
||||
Ta-da! The anatomical rendering is done!
|
||||
|
||||
Other "Structure" properties can also be adjusted in this way. In addition to **O Scalar Layer to Color**, there is also **O Scalar Layer to Factor** to convert to a single value from 0 to 1.
|
||||
49
docs/advanced.md
Normal file
@@ -0,0 +1,49 @@
|
||||
# 高级玩法
|
||||
|
||||
## 切割「结构体」
|
||||
|
||||
「结构体」可以被切割,呈现部分结构,通过 O Cut 系列节点完成。比如按下图添加 **O Cut to Region** 节点并连接,添加任意来自场景的物体作为「区域」,输入到节点:
|
||||
|
||||

|
||||
|
||||
适当调整作为「区域」物体的位置旋转,可以看到头骨结构被限制在区域范围内。
|
||||
|
||||
!!! note
|
||||
插件提供快速让物体虚化的功能,在 3D 视图模式下,右键「区域」物体,菜单选择 **Bioxel Nodes > Toggle Phantom**
|
||||
|
||||
!!! warning
|
||||
切割会增加计算量,影响实时性能,勾选 O Layer 的 Resample 来提高性能
|
||||
|
||||
|
||||
|
||||
**O Cut Small Parts** 节点,是清理神器,能快速把零碎的结构删除,只干净连续的大结构。但是计算特别耗时,注意性能。
|
||||
|
||||

|
||||
|
||||
如果你对几何节点很了解,你也可以通过 **O Cut Structure** 直接定义切割的执行范围,比如下图中,选择切割位置 X 大于 0 的部分。
|
||||
|
||||

|
||||
|
||||
|
||||
## 「结构体」属性设置
|
||||
|
||||
展开 **O Cutout by Threshold** 的 Properties,你可以直接修改各项属性值,但都只能均一设置,我们可以用场类型数据赋予差异。以颜色属性为例,比如直接接入 Position 节点,效果如下:
|
||||
|
||||

|
||||
|
||||
我们还可以把数据层的值映射为颜色渐变,这里需要用到 **O Scalar Layer to Color** 节点(这类转换功能的节点都在节点菜单,Add > O Bioxel > Utilities 下)。调整如下
|
||||
|
||||
- **O Cutout by Threshold**:Threshold 设置为 20
|
||||
- **O Scalar Layer to Color**:From Min 和 From Max 分别设置为 20 和 90
|
||||
|
||||

|
||||
|
||||
由于软组织的 CT 值小于骨质,当阈值降低,可以看到除了头骨外,附着的软组织也被呈现了出来。**O Scalar Layer to Color** 的 From Min 和 From Max,定义了颜色从 0~1 的取值范围。因此低值的软组织呈现黑色,高值的骨质呈现白色
|
||||
|
||||
我们还可以通过 Blender 5.0+ 的 **Closure** 节点来自定义映射方式。比如连接 **Color Ramp** 节点,把属于软组织的黑区,改为暗红色
|
||||
|
||||

|
||||
|
||||
哒哒!解剖渲染就做好啦👍
|
||||
|
||||
其他「结构体」属性也可以按这样的方式调整,除了 **O Scalar Layer to Color**,还有 **O Scalar Layer to Factor** 来转换为 0~1 的单值
|
||||
@@ -1,118 +0,0 @@
|
||||
# Advanced Usage
|
||||
|
||||
## Concepts
|
||||
|
||||
In the previous section, I mentioned some key concepts, I'll describe them in detail so that you can better understand the following operations.
|
||||
|
||||
### Container
|
||||
|
||||
First is the **Container**, it is the easiest to describe, you can think of it as a scene, or a solver container. it is the stage that carries all stuffs.
|
||||
|
||||
### Layer
|
||||
|
||||
Second is the **Layer**, which represents different fields of data under the same location in container of the same subject. Just as view layers in any map app, one as roads, one as satellite view, while in Bioxel, one as MRI, one as CT, one as electrical signals, etc. Some layers are for material, such as color, density, etc., we call them **Material Layer**. One container contains different layers of one subject each. Any external data imported into the container is converted into the layer.
|
||||
|
||||
### Component
|
||||
|
||||
Finally, the **Component**, which is a fragment of **Material Layer**. Multiple materials (Matters) may exist within the same area with different meanings of presentation, like objects in blender, each representing a part of the scene. Bioxel Nodes provides a series of nodes and tools that allow the user to create material layers (Components) based on the other layers (serve as source data), In the previous section, we used the CT data (layer) to make the material (matter) of skull, this process known as materialization.
|
||||
|
||||
## Attache the Muscles to the Skull
|
||||
|
||||
Multiple components can exist in one container, just as multiple objects can exist in one scene. They can be controlled individually or combined with each other to build complex scenes. Next, let's try cutouting muscle from the VHP anatomical images and attaching the muscles to the skull that created in the previous section. The anatomical images are very large, so I've cropped and scaled them down to 1/4 of their original size for ease of use. Download the file and unzip it into a new directory.
|
||||
|
||||
[VHP_M_AnatomicalImages_Head.zip](https://drive.google.com/file/d/164AjQX0tmgUpWZlleJ5i1IKHco4ytDu2/view?usp=drive_link)
|
||||
|
||||
You can also download the data directly from the official website, [https://data.lhncbc.nlm.nih.gov/public/Visible-Human/Male-Images/PNG_format/head/index.html](https://data.lhncbc.nlm.nih.gov/public/Visible-Human/Male-Images/PNG_format/head/index.html)
|
||||
|
||||
First import the CT data as described in [step by step](step_by_step.md). Then import the anatomical images, but unlike before, this time from the Geometry Nodes menu of the existing container (not the top menu), click **Bioxel Nodes > Import Volumetric Data (Init) > as Color**, locate to the unzipped folder, and select any .png file (do not multi-select, and do not select the folder). This way the imported layer will be in the same container as the previous CT data. You can also import by dragging it into the container geometry node interface instead of the 3D Viewport interface. Also note that **as Color** (not as Scalar) is clicked because the anatomical images are RGB data.
|
||||
|
||||

|
||||
|
||||
Let's take more time in the import options this time 🫡, first let's talk about what the **Original Spacing** is in the options, you can simply think of it as the original "pixel size" of a image, since the volume is 3D, its pixels (i.e., voxels) are cuboids with a length, width, and height rather than 2D rectangles. And their length, width, and height size is the **Spacing**.
|
||||
|
||||
Normally, Bioxel Nodes can read the spacing from the data header, and you don't need to fill in the value, but there is no record of that in any PNG image, so you need to input it manually. in the official description of the VHP, it is mentioned that each pixel of the anatomical images corresponds to the size of .33mm, and the thickness of each slice is 1mm, so the Original Spacing of the anatomical images should be set to `(0.33, 0.33, 1)`.
|
||||
|
||||
However, the file I provided is scaled by 1/4 for each image, so the X and Y axes need to be multiplied by 4. So the final Original Spacing should be set to `(1.33, 1.33, 1)`, which should be understandable, right? (If you are importing an official file, then it should still be set to `(0.33, 0.33, 1)`)
|
||||
Layer Name should be set to "Anatomical Images", other options remain default, click Ok.
|
||||
|
||||

|
||||
|
||||
After importing, connect the "Cutout by Hue" node (Add > Bioxel Nodes > Component > Cutout by Hue) after the newly created "Fetch Layer" node, and turn on the Slice Viewer mode preview, as shown below.
|
||||
|
||||

|
||||
|
||||
In addition to spacing, the Dicom file also records the subject's position and orientation, but those information is apparently not recorded in PNG format. This results in a mismatch between the CT data and the anatomical images in position. We need to manually align this two layers: First, set the threshold of the "Cutout by Threshold" node to 0.2 so that the full head can be cutouted and displayed. Then add "ReCenter" node before "Cutout by Hue" node and "Cutout by Threshold" node each, then add Locater to the "anatomical images" workflow (see [step by step](step_by_step.md) for details), and finally add "Join Component" node (Add > Bioxel Nodes > Component > Join Component), and connect them as shown below, with the parameters set as shown.
|
||||
|
||||

|
||||
|
||||
The "Join Component" node allows you to merge two components together. Move and rotate the Locater object so that the two components are exactly the same in position. If you're having trouble matching them up, here's the exact transform values to fill in the Locater object properties.
|
||||
|
||||

|
||||
|
||||
Next let's cutout the muscles individually.
|
||||
|
||||
First let's talk about the "Cutout by Hue" node. Literally, it cutout regions by hue of color. If you select this node and press "M" key to temporarily mute it, you'll see that the data becomes a cube with blue parts in Slice Viewer mode. the default value of Hue in the "Cutout by Hue" node is red, meaning that the node retains areas of the body that are close to red, and strip out the blue, which is on the opposite side of the red in the hue ring, leaving the human body parts.
|
||||
|
||||
If you turn down the value of Sensitivity, you'll see that the visabile part is decreasing, leaving only the part more closer to red, and the muscle happens to be red, so we can easily cutout the muscle. The color of the specimen tissue is not as vibrant as it is in the live state, and we can fine-tune the color to restore the vibrancy by using the "Set Color by Color" node (Add > Bioxel Nodes > Property > Set Color by Color).
|
||||
|
||||
To finally put it all together, connect and set the nodes as shown below, where the two colors in "Set Color by Ramp 2" node are `E7D2C5` and `FFEDEC`. If everything is working correctly, you'll get the rendering below.
|
||||
|
||||

|
||||
|
||||
You can also add "Transfrom" and "Cutter" nodes at the end and all components.
|
||||
|
||||

|
||||
|
||||
The multimodal data of VHP do not have any deformation or scaling differences, but only positional differences, so all data can be aligned easily. However, in most cases, the differences of different modalities are so great that they need to be registered first, which is not possible with Bioxel Nodes at the moment (but it is in plan). Nevertheless, you can build different components based on the same layer and combine them together. For example, based on the CT data, with the "Cutout by Range" node, you can eliminate the low value regions (fat), eliminate the high value regions (bone), and you can still get the muscle. And then attach it to the skull.
|
||||
|
||||

|
||||
|
||||
However, the CT values of brain and muscle are very close to each other, so it is extremely difficult to separate the brain from the muscle by threshold. So how should cutout the brain?
|
||||
|
||||
## Cutout the Brain
|
||||
|
||||
We can use AI technology to realize the division of brain regions, this process is called Segmentation, and the brain regions are as label. There are many models and methods for medical image segmentation, here we recommend [Total Segmentator](https://github.com/wasserth/TotalSegmentator).
|
||||
|
||||
It is an out-of-the-box CT/MRI medical image segmentation Python library. You can deploy Total Segmentator locally or process your data through the official online site [https://totalsegmentator.com](https://totalsegmentator.com).
|
||||
|
||||
Let me demonstrate the operation, we are still using the CT data from VHP. Click on "Drop DICOM.zip or ..." and select the VHP_M_CT_Head.zip file. Enter "brain" below "Selected task", press Enter to confirm. Finally click "Process data" button.
|
||||
|
||||

|
||||
|
||||
Wait for the uploading and processing, after all, you will be redirected to the following page, click "Download results" button, download and unzip segmentations.zip to any folder directory.
|
||||
|
||||

|
||||
|
||||
In case you can't get the brain segment (label), you can download it directly (without unzipping it).
|
||||
|
||||
[VHP_M_CT_Head_Brain.nii.gz](https://drive.google.com/file/d/1KGiZ3G11YLXkGszSrvWQ9kTF4TMpxUPd/view?usp=drive_link)
|
||||
|
||||
Next we import the brain segment (label) into the container in the same way as we imported the anatomical imagess(under the same container), but this time selecting **as Label**, with the Layer Name set to "Brain", and leaving the other options as default. Once the import is complete, a new "Fetch Layer" node will be added. Create and set the node as shown below, and you should be able to see the surface of brain.
|
||||
|
||||

|
||||
|
||||
Do you see the "step" like shape on surface? this is due to the low precision of the AI segmentation results. So How to addressing the issue? Select the Fetch Layer node of the brain label, right-click to pop up menu, click **Bioxel Nodes > Resample Value**, in the dialog box, change the "Smooth Size" to 3 or higher (the higher it is, the slower the calculation will be), click OK and wait for the calculation to finish. When it is done, a new layer will be added, replace the original one, is it smoother? The following figure lists different levels of smoothing.
|
||||
|
||||

|
||||
|
||||
The smoother it is, the more comfortable it looks, but it also means that more details are lost and the calculation is slower.
|
||||
|
||||
But if you cut the brain, you will find that the cross-section is homogeneous, this is because the label type layer is does not contain any modality data itself. Bioxel Nodes provides a function to fill in any layer values by label, if you set the value below brain tissue in the non-brain region of CT data, then any "Cutout" node will only keep the brain region.
|
||||
|
||||
The operation is like this, select the "Fetch Layer" node of the CT data, right-click to pop up the menu, click **Bioxel Nodes > Fill Value by Label**, in the dialog box, Label is set to the newly imported brain label layer, Fill Value is set to -100 (as long as it is less than the Hu value of the brain tissue), click OK. wait for the data processing, a new data layer will be added to the container when it is finished.
|
||||
|
||||
As shown in the following figure, connect the nodes and set the node parameters, in which the two colors of "Set Color by Ramp 2" node are `B26267` and `EBC5B7`, and the "Cutout by Range" and "Set Color by Ramp 2" node are changed to "Value" mode (the default is "Factor" mode), because the maximum and minimum values of the brain are too close to each other and difficult to adjust in "Factor" mode. To make the brain tissue look more transparent, I add the "Set Properties" (Add > Bioxel Nodes > Property > Set Properties) node at the end and changed the "Density" to 0.5.
|
||||
|
||||

|
||||
|
||||
(Still feel not smooth enough? It's really hard to get rid of "step" surface completely at the moment)
|
||||
|
||||
Now the brain is done. Finally we combine all together and you get something like the following.
|
||||
|
||||

|
||||
|
||||
🤗 If you've followed the docs up to this point, give yourself a round of applause, you've mastered this addon! If you have trouble following the docs instruction, you can download the project files to understand how the nodes work.
|
||||
|
||||
[VHP.zip](https://drive.google.com/file/d/1EHB7sxNSvJNwmoTfFnpyOSsm2M_2Y0hO/view?usp=sharing)
|
||||
|
||||
AI segmentation is an essential part of volumetric data visualization. Therefore, the future Bioxel Nodes will integrate some commonly used AI segmentation models, so that users can complete the volumetric data visualization in place!
|
||||
BIN
docs/assets/add-o-layer.png
LFS
Normal file
BIN
docs/assets/adjust-nodes.png
LFS
Normal file
|
Before Width: | Height: | Size: 41 KiB |
|
Before Width: | Height: | Size: 185 KiB |
|
Before Width: | Height: | Size: 326 KiB |
|
Before Width: | Height: | Size: 288 KiB |
|
Before Width: | Height: | Size: 412 KiB |
|
Before Width: | Height: | Size: 337 KiB |
|
Before Width: | Height: | Size: 328 KiB |
|
Before Width: | Height: | Size: 505 KiB |
|
Before Width: | Height: | Size: 340 KiB |
|
Before Width: | Height: | Size: 369 KiB |
|
Before Width: | Height: | Size: 343 KiB |
|
Before Width: | Height: | Size: 338 KiB |
|
Before Width: | Height: | Size: 351 KiB |
|
Before Width: | Height: | Size: 76 KiB |
BIN
docs/assets/connect-nodes.png
LFS
Normal file
BIN
docs/assets/cut-small-parts.png
LFS
Normal file
BIN
docs/assets/cut-structure.png
LFS
Normal file
BIN
docs/assets/cut-to-region.png
LFS
Normal file
BIN
docs/assets/import-data.png
LFS
Normal file
|
Before Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 903 KiB |
|
Before Width: | Height: | Size: 126 KiB |
BIN
docs/assets/installation.png
LFS
Normal file
|
Before Width: | Height: | Size: 40 KiB |
BIN
docs/assets/render-performance.png
LFS
Normal file
BIN
docs/assets/scalar-to-color-ramp.png
LFS
Normal file
BIN
docs/assets/scalar-to-color.png
LFS
Normal file
BIN
docs/assets/set-color-by-pos.png
LFS
Normal file
|
Before Width: | Height: | Size: 177 KiB |
|
Before Width: | Height: | Size: 278 KiB |
|
Before Width: | Height: | Size: 284 KiB |
|
Before Width: | Height: | Size: 311 KiB |
|
Before Width: | Height: | Size: 369 KiB |
|
Before Width: | Height: | Size: 350 KiB |
|
Before Width: | Height: | Size: 320 KiB |
|
Before Width: | Height: | Size: 314 KiB |
|
Before Width: | Height: | Size: 83 KiB |
|
Before Width: | Height: | Size: 86 KiB |
50
docs/basics.en.md
Normal file
@@ -0,0 +1,50 @@
|
||||
# Bacsic Usage
|
||||
|
||||
## 1. Download Data
|
||||
|
||||
Download and unzip [VHP_M_CT_Head.zip](https://drive.google.com/file/d/1bBGpt5pQ0evr-0-f4KDNRnKPoUYj2bJ-/view?usp=drive_link) to a folder.
|
||||
The data comes from [Visible Human Project (VHP)](https://www.nlm.nih.gov/research/visible/visible_human.html), which is a CT scan image of a male head.
|
||||
|
||||
## 2. Import as "Layer"
|
||||
|
||||
Add a geometry node to the cube and open the geometry node interface sidebar. Switch to the Bioxel Nodes tab (1), click the Import Data button (2), and in the file selection dialog, choose any `.dcm` file from the data folder (3), then click the Import Data button (4).
|
||||
|
||||

|
||||
|
||||
Two dialogs will pop up in sequence, click OK for both. Wait for the data import (you can check the progress bar in the Blender interface status bar at the bottom right). After success, you will see a data preview in the Bioxel Nodes sidebar. Click the Add button at the bottom (1), move the mouse to the node panel, and place the **O Layer** node (2).
|
||||
|
||||

|
||||
|
||||
The data import is complete!
|
||||
|
||||
The data cache is saved as a link in the Blender file in the form of a "Layer", and the "Layer" is loaded into geometry nodes through the **O Layer** node. Their relationship is as follows:
|
||||
|
||||
Data Cache -> Layer -> O Layer
|
||||
|
||||
## 3. Extract and Render "Structure"
|
||||
|
||||
Operations on "Layer" are done through the O Bioxel series geometry nodes.
|
||||
|
||||
We need two additional nodes: **O Cutout by Threshold** and **O Realize Structure** nodes (both are in the node menu under Add > O Bioxel > Structure), and connect them as shown below:
|
||||
|
||||

|
||||
|
||||
If successful, you will see a gray head appear in the viewport. Now let's adjust the node parameters:
|
||||
|
||||
- **O Layer**: Check Center, uncheck Resample
|
||||
- **O Cutout by Threshold**: Set Threshold to 90
|
||||
- **O Realize Structure**: Set Density to 40, check Surface
|
||||
|
||||
Rotate the object, adjust the light position, set the renderer to Cycles, and the final effect is shown below:
|
||||
|
||||

|
||||
|
||||
Now we have completed the volumetric rendering of the head CT data!
|
||||
|
||||
Let's review the execution logic: First, cutout the "Structure" from the "Layer". As the name suggests, "Structure" is responsible for storing biological tissue structure, but its data type is volumetric and cannot be seen directly. It requires **O Realize Structure** to present the "Structure".
|
||||
|
||||
## 4. Save Data Cache (Optional)
|
||||
|
||||
Since the data cache is only saved as a link in the Blender file, passing only the Blender file to other devices will cause the "Layer" to lose its cache. Click the Save button in the Bioxel Nodes tab, and select a location to save the data cache to manage the cache resource.
|
||||
|
||||
Just like images, when sharing, send both the data cache and the Blender file together.
|
||||
51
docs/basics.md
Normal file
@@ -0,0 +1,51 @@
|
||||
# 入门
|
||||
|
||||
## 1. 下载数据
|
||||
|
||||
下载并解压到文件夹中 [VHP_M_CT_Head.zip](https://drive.google.com/file/d/1bBGpt5pQ0evr-0-f4KDNRnKPoUYj2bJ-/view?usp=drive_link)
|
||||
数据来自 [Visible Human Project (VHP)](https://www.nlm.nih.gov/research/visible/visible_human.html)这是一个男性头部的 CT 扫描图像
|
||||
|
||||
## 2. 导入为「数据层」
|
||||
|
||||
给立方体添加几何节点,并打开几何节点界面侧边栏。切换到 Bioxel Nodes 分页(1),点击 Import Data 按钮(2),在文件选择对话框中,选择数据文件夹中任意一个`.dcm`文件(3),点击 Import Data 按钮(4)
|
||||
|
||||

|
||||
|
||||
依次会弹出两个对话框,都点击 OK 按钮,等待数据导入(可查看 Blender 界面右下角状态栏的进度条)成功后可以看到 Bioxel Nodes 侧边栏多了数据预览画面。点击下方的 Add 按钮(1),鼠标移动到节点面板,放置 **O Layer** 节点(2)
|
||||
|
||||

|
||||
|
||||
数据的导入就完成啦👍
|
||||
|
||||
数据缓存在主目录里,以「数据层(Layer)」形式添加在 Blender 文件中,「数据层」通过 **O Layer** 节点装载到几何节点。它们的关系如下:
|
||||
|
||||
数据缓存 -> 数据层 -> O Layer
|
||||
|
||||
|
||||
## 3. 提取并渲染「结构体」
|
||||
|
||||
对「数据层」的操作通过 O Bioxel 系列几何节点完成。
|
||||
|
||||
我们需要额外两个节点,**O Cutout by Threshold** 和 **O Realize Structure** 节点(它们都在节点菜单,Add > O Bioxel > Structure 下),并按下图连接:
|
||||
|
||||

|
||||
|
||||
如果成功,可以看到视图中出现了灰色的头部。接下来我们调整节点参数:
|
||||
|
||||
- **O Layer**:勾选 Center,取消 Resample
|
||||
- **O Cutout by Threshold**:Threshold 设置为 90
|
||||
- **O Realize Structure**:Density 设置为 40,勾选 Surface
|
||||
|
||||
调整物体转向、灯位置,设置渲染器为 Cycles,最终效果如下图:
|
||||
|
||||

|
||||
|
||||
这样我们就完成了头部 CT 数据的体积渲染👍
|
||||
|
||||
简单捋一下执行逻辑,「数据层」先被剪出(Cutout)为「结构体」。「结构体」顾名思义就是负责储存生物组织结构的对象,但它本身数据类型是体积,并不能直接被看到。需要 **O Realize Structure** 来呈现「结构体」
|
||||
|
||||
## 4. 另存数据缓存(可选)
|
||||
|
||||
由于数据缓存只是以链接形式保存在 Blender 文件中,所以只传递 Blender 文件给其他设备,会导致「数据层」遗失缓存。点击 Bioxel Nodes 分页中 Save 按钮,选择数据缓存的另存位置来管理缓存资源。
|
||||
|
||||
就像图片一样,传递时把数据缓存和 Blender 文件一起发送。
|
||||
39
docs/dataset.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# 支持的格式
|
||||
|
||||
迫不及待想使用自己的数据来体验插件了?以下是当前支持的格式列表。
|
||||
|
||||
| 格式 | 扩展名 |
|
||||
| ------ | ---------------------------------------- |
|
||||
| DICOM | .dcm, .DCM, .DICOM, .ima, .IMA |
|
||||
| BMP | .bmp, .BMP |
|
||||
| JPEG | .jpg, .JPG, .jpeg, .JPEG |
|
||||
| PNG | .png, .PNG |
|
||||
| TIFF | .tif, .TIF, .tiff, .TIFF |
|
||||
| Nifti | .nia, .nii, .nii.gz, .hdr, .img, .img.gz |
|
||||
| Nrrd | .nrrd, .nhdr |
|
||||
| HDF5 | .hdf, .h4, .hdf4, .he2, .h5, .hdf5, .he5 |
|
||||
| OME | .ome.tiff, .ome.tif |
|
||||
| MRC | .mrc, .mrc.gz, .map, .map.gz |
|
||||
|
||||
尽管我尽了最大努力,仍然无法实现对所有体数据格式的完美支持,我将持续努力改进。
|
||||
|
||||
## 公开数据库
|
||||
|
||||
如果您没有体数据,可以从一些公开数据库下载。
|
||||
|
||||
**请注意,虽然它们是公开的且可供下载,但并不意味着您可以将其用于任何目的!请务必查看网站上的可用范围说明。**
|
||||
|
||||
| 来源 | 对象 |
|
||||
| ------------------------------------------------------------------------------------ | ------------------ |
|
||||
| [MorphoSource](https://www.morphosource.org/) | 开放研究数据 |
|
||||
| [Dryad](https://datadryad.org) | 开放研究数据 |
|
||||
| [Cell Image Library](http://cellimagelibrary.org/home) | 细胞 |
|
||||
| [OpenOrganelle](https://openorganelle.janelia.org/datasets) | 细胞 |
|
||||
| [Allen Cell Explorer](https://www.allencell.org/3d-cell-viewer.html) | 细胞 |
|
||||
| [EMDB](https://www.ebi.ac.uk/emdb/) | 蛋白质、病毒 |
|
||||
| [IDC](https://portal.imaging.datacommons.cancer.gov/explore/) | 医学图像 |
|
||||
| [Embodi3D](https://www.embodi3d.com/files/category/37-medical-scans/) | 医学图像 |
|
||||
| [Github](https://github.com/sfikas/medical-imaging-datasets) | 医学图像 |
|
||||
| [NIHR](https://nhsx.github.io/open-source-imaging-data-sets/) | 医学图像 |
|
||||
| [Medical Segmentation Decathlon](http://medicaldecathlon.com/) | 医学图像 |
|
||||
| [Visible Human Project](https://www.nih.gov/research/visible/visible_human.html) | 医学图像 |
|
||||
15
docs/faq.en.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# FAQ
|
||||
|
||||
## Nothing in the scene when rendering?
|
||||
|
||||
If you're using the Cycles renderer with GPU, make sure your GPU supports "Optix", as Bioxel Nodes relies on OSL (Open shader language) for volumetric rendering, otherwise you'll have to use the CPU for rendering.
|
||||
|
||||
If you're using the EEVEE renderer, this issue is due to EEVEE not loading shaders for some unknown reason, save the file and restart Blender to fix it.
|
||||
|
||||
## After updating the addon, the nodes in the file have turned red?
|
||||
|
||||
This is because the version of the nodes in the file does not match the current version of the addon after updating.
|
||||
|
||||
If you still want to edit the file with Bioxel Nodes, you can only roll back the addon version to the version that corresponds to the nodes.
|
||||
|
||||
If you just want the file to work and you won't rely on Bioxel Nodes any more, then you can just click **Bioxel Nodes > Relink Node Library >** in the top menu and select the corresponding version. Check to see if the nodes are working and rendering properly, and when everything is OK, click **Bioxel Nodes > Save Node Library** and select the save location in the dialog box.
|
||||
16
docs/faq.md
@@ -1,15 +1,15 @@
|
||||
# FAQ
|
||||
# 常见问题
|
||||
|
||||
## Nothing in the scene when rendering?
|
||||
## 渲染时场景什么都没有?
|
||||
|
||||
If you're using the Cycles renderer with GPU, make sure your GPU supports "Optix", as Bioxel Nodes relies on OSL (Open shader language) for volumetric rendering, otherwise you'll have to use the CPU for rendering.
|
||||
如果您使用 GPU 进行 Cycles 渲染,请确保您的 GPU 支持"Optix",因为 Bioxel Nodes 依赖 OSL(Open Shader Language)进行体渲染,否则您必须使用 CPU 进行渲染。
|
||||
|
||||
If you're using the EEVEE renderer, this issue is due to EEVEE not loading shaders for some unknown reason, save the file and restart Blender to fix it.
|
||||
如果您使用 EEVEE 渲染器,此问题是因为 EEVEE 出于未知原因未加载着色器,保存文件并重启 Blender 即可修复。
|
||||
|
||||
## After updating the addon, the nodes in the file have turned red?
|
||||
## 更新插件后,文件中的节点变红了?
|
||||
|
||||
This is because the version of the nodes in the file does not match the current version of the addon after updating.
|
||||
这是因为文件中节点的版本与更新后插件的版本不匹配。
|
||||
|
||||
If you still want to edit the file with Bioxel Nodes, you can only roll back the addon version to the version that corresponds to the nodes.
|
||||
如果您仍想使用 Bioxel Nodes 编辑文件,只能将插件回滚到与节点对应的版本。
|
||||
|
||||
If you just want the file to work and you won't rely on Bioxel Nodes any more, then you can just click **Bioxel Nodes > Relink Node Library >** in the top menu and select the corresponding version. Check to see if the nodes are working and rendering properly, and when everything is OK, click **Bioxel Nodes > Save Node Library** and select the save location in the dialog box.
|
||||
如果您只想让文件正常工作,不再依赖 Bioxel Nodes,那么您只需点击顶部菜单 **Bioxel Nodes > Relink Node Library >**,然后选择相应的版本。检查节点是否正常工作并正确渲染,一切正常后,点击 **Bioxel Nodes > Save Node Library**,在对话框中选择保存位置。
|
||||
@@ -1,39 +0,0 @@
|
||||
# Improve Performance
|
||||
|
||||
Volume reconstruction and volume rendering are very consuming computation, I believe that this add-on's experience is terrible on poorly hardware. here are tips to improve the add-on performance.
|
||||
|
||||
## Use Low-Res Data as Preview
|
||||
|
||||
The addon provides data resample function, the operation is as follows. First, in the container's geometry node, select the layer you need to resample, right-click **Bioxel Nodes > Resample Value**, in the dialog box, change the "Bioxel Size" value to twice or more than the current value, click OK. the addon will create a low-res version of the layer and load it into the container's geometry node.
|
||||
|
||||

|
||||
|
||||
You can see that the speed of the reconstruction has been reduced from 240 ms to 37 ms, making it possible to compute in almost real-time, and improving the speed of the feedback of the changing the parameters. Once you are satisfied with the adjustment, you can then connect the original layer to the nodes. This tip can greatly improve the operation experience of the node.
|
||||
|
||||
## Raise the Step Rate of a Container
|
||||
|
||||
Step rate is a key setting in volume rendering. The higher the step rate, the faster the rendering will be, but at the same time, the thinner the volume will look. If you want to have a very thin effect, or if you don't need to cut through component, you can always set the step rate high, you can adjust step rate in the render settings globaly. However, I recommend you to adjust the step rate of the container separately, so that it doesn't affect the rendering of the other volume in the Blender file, do as follows.
|
||||
|
||||
In the container's geometry nodes panel menu, click **Bioxel Nodes > Change Container Properties**, in the dialog box, raise the "Step Rate" value (up to 100) and click OK.
|
||||
|
||||

|
||||
|
||||
You can see that the rendering speed is much higher, but at the same time the cuts look blurry and transparent.
|
||||
|
||||
## Balance rendering settings
|
||||
|
||||
I list some of the settings that affect the volume rendering most, so you can find the most balanced settings for your needs.
|
||||
|
||||
- **Light Paths > Max Bounces > Volume** affects the number of bounces a volume has, the higher the value, the more transparent it will look.
|
||||
|
||||
- **Light Paths > Max Bounces > Transparent** affects the number of times transparent surfaces are transmitted, the higher the value, the more transparent it will look.
|
||||
|
||||
- **Volumes > Step Rate Render | Viewport** affects the volume rendering step, the smaller the value, the more detailed the volume will look
|
||||
|
||||
Bioxel Nodes provides some render setting presets for quick setup. In the top menu, click **Bioxel Nodes > Render Setting Presets**, including Performance (left), Balance (center), and Quality (right). Here is a comparison of them.
|
||||
|
||||

|
||||
|
||||
## Rendering with EEVEE
|
||||
|
||||
EEVEE doesn't render volume as well as Cycles, but it does have the advantage of rendering the volumetric data, and is even a better choice if you want to get a clear view of slice. And EEVEE's real-time rendering make it possible to create interactive stuff in Blender.
|
||||
59
docs/index.en.md
Normal file
@@ -0,0 +1,59 @@
|
||||
**v2.0.x has been released, supporting only Blender 5.0+. The usage is completely different from before and is not compatible with old version files. See http://docs.omoolab.xyz/bioxelnodes/2.0.x/en/basics/**
|
||||
|
||||
# Bioxel Nodes
|
||||
|
||||
[](https://blender.org/)
|
||||

|
||||

|
||||

|
||||
|
||||
[](https://discord.gg/pYkNyq2TjE)
|
||||
|
||||
Bioxel Nodes is a Blender addon for scientific volumetric data visualization. It using Blender's powerful **Geometry Nodes** and **Cycles** to process and render volumetric data.
|
||||
|
||||

|
||||
|
||||
- Realistic rendering result, also support EEVEE NEXT.
|
||||
- Support multiple formats.
|
||||
- Support 4D volumetric data.
|
||||
- All kinds of cutters.
|
||||
- Simple and powerful nodes.
|
||||
- Based on blender natively, can work without addon.
|
||||
|
||||
**Read the [getting started](https://docs.omoolab.xyz/bioxelnodes/latest/en/installation) to begin your journey into visualizing volumetric data!**
|
||||
|
||||
Welcome to our [discord server](https://discord.gg/pYkNyq2TjE), if you have any problems with this add-on.
|
||||
|
||||
## Support Multiple Formats
|
||||
|
||||
| Format | EXT |
|
||||
| ------ | ---------------------------------------- |
|
||||
| DICOM | .dcm, .DCM, .DICOM, .ima, .IMA |
|
||||
| BMP | .bmp, .BMP |
|
||||
| JPEG | .jpg, .JPG, .jpeg, .JPEG |
|
||||
| PNG | .png, .PNG |
|
||||
| TIFF | .tif, .TIF, .tiff, .TIFF |
|
||||
| Nifti | .nia, .nii, .nii.gz, .hdr, .img, .img.gz |
|
||||
| Nrrd | .nrrd, .nhdr |
|
||||
| HDF5 | .hdf, .h4, .hdf4, .he2, .h5, .hdf5, .he5 |
|
||||
| OME | .ome.tiff, .ome.tif |
|
||||
| MRC | .mrc, .mrc.gz, .map, .map.gz |
|
||||
|
||||
## Support 4D volumetric data
|
||||
|
||||

|
||||
|
||||
🥰 4D volumetric data can also be imported into Blender.
|
||||
|
||||
## Support EEVEE NEXT
|
||||
|
||||

|
||||
|
||||
👍 EEVEE NEXT is absolutely AWESOME! Bioxel Nodes is fully support EEVEE NEXT now!
|
||||
|
||||
|
||||
## Roadmap
|
||||
|
||||
- Better multi-format import experience
|
||||
- One-click bake model with texture
|
||||
- AI Segmentation to Generate Labels
|
||||
@@ -1,4 +1,4 @@
|
||||
[中文文档](https://uj6xfhbzp0.feishu.cn/wiki/LPKEwjooSivxjskWHlCcQznjnNf?from=from_copylink)
|
||||
**v2.0.X 已发布,仅支持 Blender 5.0+,使用方式和之前截然不同,也无法兼容旧版本文件。使用方式查看 http://docs.omoolab.xyz/bioxelnodes/2.0.x/basics/**
|
||||
|
||||
# Bioxel Nodes
|
||||
|
||||
@@ -9,58 +9,50 @@
|
||||
|
||||
[](https://discord.gg/pYkNyq2TjE)
|
||||
|
||||
Bioxel Nodes is a Blender addon for scientific volumetric data visualization. It using Blender's powerful **Geometry Nodes** and **Cycles** to process and render volumetric data.
|
||||
Bioxel Nodes 是一款用于科学体数据可视化的 Blender 插件。它利用 Blender 强大的 **几何节点 (Geometry Nodes)** 和 **Cycles** 渲染器来处理和渲染体数据。
|
||||
|
||||

|
||||
|
||||
- Realistic rendering result, also support EEVEE NEXT.
|
||||
- Support multiple formats.
|
||||
- Support 4D volumetric data.
|
||||
- All kinds of cutters.
|
||||
- Simple and powerful nodes.
|
||||
- Based on blender natively, can work without addon.
|
||||
- 逼真的渲染效果,同时也支持 EEVEE NEXT
|
||||
- 支持多种数据格式
|
||||
- 支持 4D 体数据
|
||||
- 多种切割工具
|
||||
- 简洁而强大的节点系统
|
||||
- 基于 Blender 原生开发,插件卸载后仍可正常工作
|
||||
|
||||
**Read the [getting started](https://omoolab.github.io/BioxelNodes/latest/installation) to begin your journey into visualizing volumetric data!**
|
||||
**阅读[安装指南](installation.md)开始您的体数据可视化之旅!**
|
||||
|
||||
Welcome to our [discord server](https://discord.gg/pYkNyq2TjE), if you have any problems with this add-on.
|
||||
如果您在使用过程中遇到任何问题,欢迎加入我们的 [Discord 服务器](https://discord.gg/pYkNyq2TjE)。
|
||||
|
||||
## Support Multiple Formats
|
||||
## 支持多种格式
|
||||
|
||||
| Format | EXT |
|
||||
| ------ | ---------------------------------------- |
|
||||
| DICOM | .dcm, .DCM, .DICOM, .ima, .IMA |
|
||||
| BMP | .bmp, .BMP |
|
||||
| JPEG | .jpg, .JPG, .jpeg, .JPEG |
|
||||
| PNG | .png, .PNG |
|
||||
| TIFF | .tif, .TIF, .tiff, .TIFF |
|
||||
| Nifti | .nia, .nii, .nii.gz, .hdr, .img, .img.gz |
|
||||
| Nrrd | .nrrd, .nhdr |
|
||||
| HDF5 | .hdf, .h4, .hdf4, .he2, .h5, .hdf5, .he5 |
|
||||
| OME | .ome.tiff, .ome.tif |
|
||||
| MRC | .mrc, .mrc.gz, .map, .map.gz |
|
||||
| 格式 | 扩展名 |
|
||||
| ----- | ---------------------------------------- |
|
||||
| DICOM | .dcm, .DCM, .DICOM, .ima, .IMA |
|
||||
| BMP | .bmp, .BMP |
|
||||
| JPEG | .jpg, .JPG, .jpeg, .JPEG |
|
||||
| PNG | .png, .PNG |
|
||||
| TIFF | .tif, .TIF, .tiff, .TIFF |
|
||||
| Nifti | .nia, .nii, .nii.gz, .hdr, .img, .img.gz |
|
||||
| Nrrd | .nrrd, .nhdr |
|
||||
| HDF5 | .hdf, .h4, .hdf4, .he2, .h5, .hdf5, .he5 |
|
||||
| OME | .ome.tiff, .ome.tif |
|
||||
| MRC | .mrc, .mrc.gz, .map, .map.gz |
|
||||
|
||||
## Support 4D volumetric data
|
||||
## 支持 4D 体数据
|
||||
|
||||

|
||||
|
||||
🥰 4D volumetric data can also be imported into Blender.
|
||||
4D 体数据也可以导入到 Blender 中。
|
||||
|
||||
## Support EEVEE NEXT
|
||||
## 支持 EEVEE NEXT
|
||||
|
||||

|
||||
|
||||
👍 EEVEE NEXT is absolutely AWESOME! Bioxel Nodes is fully support EEVEE NEXT now! However, there are some limitations:
|
||||
EEVEE NEXT 太棒了!Bioxel Nodes 现在全面支持 EEVEE NEXT!
|
||||
|
||||
1. Only one cutter supported.
|
||||
2. EEVEE result is not that great as Cycles does.
|
||||
## 路线图
|
||||
|
||||
## Known Limitations
|
||||
|
||||
- Only works with Cycles CPU , Cycles GPU (OptiX), EEVEE
|
||||
- Section surface cannot be generated when convert to mesh (will be supported soon)
|
||||
|
||||
## Roadmap
|
||||
|
||||
- Better multi-format import experience
|
||||
- One-click bake model with texture
|
||||
- AI Segmentation to Generate Labels
|
||||
- 更完善的多格式导入体验
|
||||
- 一键烘焙带纹理模型
|
||||
- AI 分割生成标签
|
||||
|
||||
22
docs/installation.en.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# Installation
|
||||
|
||||
!!! warning
|
||||
**v2.0.x only supports Blender 5.0 and above**
|
||||
|
||||
The add-on supports multiple installation methods, choose one.
|
||||
|
||||
## Blender Preferences (Recommended)
|
||||
|
||||
Click the top menu **Edit > Preferences**, search for "biox" in the "Get Extensions" area. Then click Install. Due to the large add-on size (60~100MB), you may need to wait for a while.
|
||||
|
||||

|
||||
|
||||
## Blender Official Extensions Website
|
||||
|
||||
Visit [https://extensions.blender.org/add-ons/bioxelnodes/](https://extensions.blender.org/add-ons/bioxelnodes/)
|
||||
Click Get Add-on, open Blender, drag the add-on into Blender and follow the prompts to install.
|
||||
|
||||
## Manual Installation
|
||||
|
||||
You can also download `BioxelNodes.{version}.zip` from [here](https://github.com/OmooLab/BioxelNodes/releases/latest) for manual installation.
|
||||
Click the top menu **Edit > Preferences**, select **Add-ons > Install from Disk**, then choose the Zip file you downloaded.
|
||||
@@ -1,19 +1,22 @@
|
||||
# Installation
|
||||
# 安装
|
||||
|
||||
**Currently only support Blender 4.2 or above, make sure you have the correct version of Blender.**
|
||||
!!! warning
|
||||
**v2.0.x 仅支持 Blender 5.0 及以上版本**
|
||||
|
||||
## Install in Blender (recommended)
|
||||
插件支持多种安装方式,选其中之一即可
|
||||
|
||||
This is the most recommended way, in the top menu, click **Edit > Preferences**, in "Get Extensions" Section, enter "bio" in the search box, then click Install. due to the add-on size (25MB~50MB) you may need to wait a while.
|
||||
## Blender 偏好设置(推荐)
|
||||
|
||||

|
||||
点击顶部菜单 **Edit > Preferences**,在 "Get Extensions" 区域搜索 "biox"。然后点击 Install。由于插件体积较大(60~100MB),可能需要等待一段时间。
|
||||
|
||||
## Blender Official Extensions Website
|
||||

|
||||
|
||||
Or you can visit the Blender official extensions website at [https://extensions.blender.org/add-ons/bioxelnodes/](https://extensions.blender.org/add-ons/bioxelnodes/)
|
||||
Click Get Add-on, open Blender, drag in Blender and follow the instructions to install.
|
||||
## Blender 官方扩展网站
|
||||
|
||||
## Manual Install
|
||||
访问 [https://extensions.blender.org/add-ons/bioxelnodes/](https://extensions.blender.org/add-ons/bioxelnodes/)
|
||||
点击 Get Add-on,打开 Blender,将插件拖入并按照提示安装。
|
||||
|
||||
You can also install _BioxelNodes\_{version}.zip_ manually by downloading from [bere](https://github.com/OmooLab/BioxelNodes/releases/latest).
|
||||
In the top menu, click **Edit > Preferences**, **Add-ons > Install from Disk** and select the Zip file you just downloaded.
|
||||
## 手动安装
|
||||
|
||||
您也可以从 [这里](https://github.com/OmooLab/BioxelNodes/releases/latest) 下载 `BioxelNodes.{version}.zip` 进行手动安装。
|
||||
点击顶部菜单 **Edit > Preferences**,选择 **Add-ons > Install from Disk**,然后选择您下载的 Zip 文件。
|
||||
|
||||
25
docs/performance.en.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Improve Performance
|
||||
|
||||
Voxel reconstruction and voxel rendering are very computation-intensive. Here are some tips to improve the add-on's performance.
|
||||
|
||||
## Use Low-Resolution Data as Preview
|
||||
|
||||
The resolution of voxels geometrically affects computational efficiency. Enabling Resample on O Layer can greatly improve calculation speed. You can uncheck it when you need to render for real. The Layer Nodes panel in the Bioxel Nodes tab lists all O Layers added in the current geometry nodes. You can uniformly manage whether Resample is enabled and the degree of resampling.
|
||||
|
||||
## Balanced Rendering Settings
|
||||
|
||||
I list some settings that have the greatest impact on volume rendering, so you can find the most suitable balance for your needs.
|
||||
|
||||
- **Light Paths > Max Bounces > Volume** affects the number of bounces for volume data. The higher the value, the more transparent the volume data appears.
|
||||
|
||||
- **Light Paths > Max Bounces > Transparent** affects the number of times transparent surfaces are transmitted. The higher the value, the more transparent the transparent surfaces appear.
|
||||
|
||||
- **Volumes > Step Rate Render | Viewport** affects the step size of volume rendering. The smaller the value, the more detailed the volume data appears.
|
||||
|
||||
Bioxel Nodes provides some render setting presets for quick configuration. Click the top menu **Bioxel Nodes > Render Setting Presets**, including Performance (left), Balance (center), and Quality (right). Here is a comparison:
|
||||
|
||||

|
||||
|
||||
## Rendering with EEVEE
|
||||
|
||||
EEVEE doesn't render volume as well as Cycles, but it does have the advantage of rendering volumetric data. If you want to get a clear slice view, it is even a better choice. EEVEE's real-time rendering makes it possible to create interactive content in Blender.
|
||||
25
docs/performance.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# 提升性能
|
||||
|
||||
体素重建和体素渲染是非常消耗计算资源的,以下是一些提升插件性能的建议。
|
||||
|
||||
## 使用低分辨率数据作为预览
|
||||
|
||||
体素的分辨率几何倍地影响计算效率,O Layer 的 Resample 开启可以大大提高计算速度。当你需要正式渲染的时候再关闭即可。在 Bioxel Nodes 分页的 Layer Nodes 面板罗列了当前几何节点中添加的所有 O Layer,你可以统一管理是否开启 Resample,以及程度。
|
||||
|
||||
## 平衡的渲染设置
|
||||
|
||||
我列出了一些对体渲染影响最大的设置,以便您找到最适合自己的平衡点。
|
||||
|
||||
- **Light Paths > Max Bounces > Volume** 影响体数据的反弹次数,值越高,体数据看起来越透明。
|
||||
|
||||
- **Light Paths > Max Bounces > Transparent** 影响透明表面透射的次数,值越高,透明表面看起来越透明。
|
||||
|
||||
- **Volumes > Step Rate Render | Viewport** 影响体渲染的步长,值越小,体数据看起来越精细。
|
||||
|
||||
Bioxel Nodes 提供了一些渲染设置预设以便快速配置。点击顶部菜单 **Bioxel Nodes > Render Setting Presets**,包括 Performance(左侧)、Balance(中间)和 Quality(右侧)。以下是它们的比较。
|
||||
|
||||

|
||||
|
||||
## 使用 EEVEE 渲染
|
||||
|
||||
EEVEE 渲染体数据不如 Cycles,但它确实有渲染体数据的优势,如果您想获得清晰的切片视图,它甚至是更好的选择。EEVEE 的实时渲染使得在 Blender 中创建交互式内容成为可能。
|
||||
@@ -1,97 +0,0 @@
|
||||
# Step by Step
|
||||
|
||||
## Download Data
|
||||
|
||||
Here is the open data from [Visible Human Project (VHP)](https://www.nlm.nih.gov/research/visible/visible_human.html) for you to learn how to use this addon. It is a CT scan image of a male head, download and unzip it to a new directry for later usage.
|
||||
|
||||
[VHP_M_CT_Head.zip](https://drive.google.com/file/d/1bBGpt5pQ0evr-0-f4KDNRnKPoUYj2bJ-/view?usp=drive_link)
|
||||
|
||||
VHP original radiology data was shared in the proprietary format that predated DICOM, complicating its use. Now all data has been harmonized to standard DICOM and released in [NCI Imaging Data Commons (IDC)](https://portal.imaging.datacommons.cancer.gov/), you also can download data from IDC by yourself.
|
||||
|
||||
## Import Data
|
||||
|
||||
In the top menu, click **Bioxel Nodes > Import Volumetric Data (Init) > as Scalar**, locate to the unzipped folder, select any DICOM file (don't select more than one, and don't select the folder either), and click **Import as Scalar**.
|
||||
|
||||

|
||||
|
||||
You can also choose to import data by dragging one DICOM file into the 3D viewport (some DICOM files don't have extension suffix and can't be dragged in).
|
||||
|
||||
The process of reading the data may take a while, the bottom right corner of the Blender interface will show you the progress of the reading, and a dialog box will pop up when the reading is successful. Ignore all the options for now and just click OK, I will explain the purpose of these options later.
|
||||
|
||||
The import process involves data conversion, so there is more waiting time, and the progress of the import is displayed in the lower right corner of the interface. After importing, the addon will create a new object, with a new geometry nodes that will serve as a "workbench" for manipulating the data, the new object is called the **Container**. The newly imported data is stored in the Container as a **Layer**, which is loaded into the Container's Geometry node via the "Fetch Layer" node (the red one), and be converted into a **Component** that can be rendered.
|
||||
|
||||

|
||||
|
||||
Next, let's preview the data in Blender.
|
||||
|
||||
In the container's geometry nodes panel menu, click **Bioxel Nodes > Add a Slicer**. The addon will insert a node named "Slice" between the "Fetch Layer" and the "Output" and create a new plane object named "Slicer". Click the "Slice Viewer" button in the upper right corner of the 3D viewport to enter the preview mode, then move and rotate the "Slicer" object. You will see a slice image of the data, which should be familiar to anyone who has used any DICOM viewing software.
|
||||
|
||||

|
||||
|
||||
(If the volume disappears when you click the "Slice Viewer" button, save the file and restart Blender, it should be fixed, or you can turn on the Cycles rendering to see the slicer plane as well. The issue is caused by EEVEE's failure of reloading the shaders.)
|
||||
|
||||
The "Slicer" node is used to display the slices of the data, with an external object as the location of the slice plane. This step is not necessary for visualization, but it provides a quick way to preview the data in Blender for user perception. Next, let's turn the volumetric data into a renderable object.
|
||||
|
||||
## Cutout the Skull
|
||||
|
||||
Bone tends to have much higher CT values than soft tissue, so you can split bone and soft tissue by setting a threshold. In the Geometry Nodes panel menu of the container, click **Add > Bioxel Nodes > Component > Cutout by Threshold** to add a "Cutout" node and connect it between the "Fetch Layer" node and the "Output", and then set the "Threshold" parameter of the "Cutout by Threshold" node to 0.3 and turn on the "With Surface" option. Switch to viewport shading to "Render Preview". The node graph and the render result are shown below.
|
||||
|
||||

|
||||
|
||||
If you want the render result to be consistent with the above image, you also need to change the default light object type from "Point" to "Area" to increase the brightness, and change the Look in Color Management to "High Contrast".
|
||||
|
||||
You can understand the role of the "Threshold" parameter in shaping the output by changing it. If you feel very laggy while draging the parameter, you can temporarily turn off the "With Surface" option in the "Cutout" node. When you are satisfied, turn it on again. In addition, the volume rendering is very computationally intensive, which is also a major cause of the lag, so you can adjust the parameters in "Slice Viewer" mode first, and then do the Cycles rendering when you are satisfied.
|
||||
|
||||
You may consider using GPU for faster rendering, but please note that Bioxel Nodes only supports Optix GPUs due to its dependency on OSL (Open shader language), and the first time you turn on GPU rendering, you may need to wait for Blender to load the appropriate dependencies (the screen will get stuck), so please be patient.
|
||||
|
||||
Although the output component looks like a mesh object, it retains its internal information through its volume, so when you cut through the component, you should see an inhomogeneous cross-section made up of volume, rather than just an empty shell like any mesh object. Let's cut the skull to see its complex internal structure.
|
||||
|
||||
## Cut and Color
|
||||
|
||||
In the container's geometry nodes panel menu, click **Bioxel Nodes > Add a Cutter > Plane Cutter**, the addon will insert a "Cut" node and a "Object Cutter" node. Also, it will create a new plane object named "Plane Cutter" to the scene, at this point you should be able to see that the skull has been cut through as expected.
|
||||
|
||||
Just like the "Slicer" object, move and rotate the "Plane Cutter" and the position and direction of the cut will change accordingly. Please adjust the Cutter object to a vertical orientation so that it cuts the skull vertically, as shown below.
|
||||
|
||||

|
||||
|
||||
The CT value of the skull is inhomogeneous, which reflects the difference in substance density of the bone. We can enhance the display of this difference by coloring. In the Geometry Nodes panel menu of the container, click **Add > Bioxel Nodes > Propetry > Set Color by Ramp 5** to add the "Set Color" node and connect it after any node. Set the node's parameters "From Min" to 0.3 and "From Max" to 0.5, as shown below.
|
||||
|
||||

|
||||
|
||||
When rendering is turned on, you can clearly see that the calvaria and teeth are colored red, meaning that the bone in these areas is denser. You can try to adjust the parameters of the "Set Color" node to recognize their roles. If you feel laggy when draging the parameters, you can temporarily turn off "With Surface" and switch to "Slice Viewer" mode.
|
||||
|
||||
## Transformation
|
||||
|
||||
You may find that the position of the skull is a bit off the origin, this is due to the fact that the addon keeps the position information from the original data record during the import process. If you need to change the position, do not move the container (object) directly as you would in 3D viewport; the addon provides dedicated "Transform" node to handle transformations.
|
||||
|
||||
In the Geometry Nodes panel menu of the container, click **Bioxel Nodes > Add a Locator**, the addon will insert the "Transform Parent" node and create a new empty object named "Locator". If you move, rotate, or scale the "Locator", the skull will Transform as well. If you also want the origin of the rotational transformation to be set at the geometric center of the skull, just add a "ReCenter" node (Add > Bioxel Nodes > Transform > ReCenter) in front of the "Transform Parent" node, as shown below.
|
||||
|
||||

|
||||
|
||||
Being used to moving objects directly in the 3D viewport, you may find it strange to have an extra step to transform component like this. This is in consideration of the fact that there may be multiple components involved in one container with different transform needs, as well as future development plans for resampling mechanism, which I'll explain in more detail later.
|
||||
|
||||
## Surface Mesh
|
||||
|
||||
A mesh, made up of vertexs and faces, is the "greatest common" in the 3D world. Therefore, in order to be compatible with other 3D workflow, the addon provides the "To Surface" node (Add > Bioxel Nodes > Component > ToSurface), which converts the component into a mesh. Note that the surface mesh is not editable in the container's geometry node, and can only be connected to "Transform" and "Shader" nodes.
|
||||
|
||||
As shown below, you can connect "Slime Shader" node (Add > Bioxel Nodes > Surface > Slime Shader) after the "To Surface" node to give the surface a shader, or connect "Transform" nodes.
|
||||
|
||||

|
||||
|
||||
If you want to edit the mesh, in the Geometry Nodes panel menu of the container, click **Bioxel Nodes > Extract from Container > Extract Mesh**, the addon will create a new mesh model object prefixed with the container name, and then you can perform the usual 3D operations, such as digitally sculpting, animating, exporting to 3D print format stl, etc.
|
||||
|
||||
## Deliver Blender File
|
||||
|
||||
The layers cache is stored in a temporary folder, while the addon's custom nodes are linked to the node library file in addon directory. Both of them are exist locally by default, and if you only deliver the Blender file to other devices, the file will not work properly because the resources are missing.
|
||||
|
||||
Therefore, you need to save all temporary files before you deliver the Blender file. The procedure is simple:
|
||||
|
||||
1. Save the Blender file.
|
||||
2. in the top menu, click **Bioxel Nodes > Save Node Library**, and set the relative path.
|
||||
3. in the top menu, click **Bioxel Nodes > Save All Layers Cache** and set the relative path.
|
||||
|
||||
Zip the Blender file together with the local node library file and the layer cache files (there may be more than one).
|
||||
|
||||

|
||||
|
||||
🤗 If you can follow the documentation up to this point, you're already started!
|
||||
@@ -1,20 +1,28 @@
|
||||
[data-md-color-scheme="slate"] {
|
||||
@import url("https://fontsapi.zeoseven.com/292/main/result.css");
|
||||
@import url("https://fontsapi.zeoseven.com/293/main/result.css");
|
||||
|
||||
/* [data-md-color-scheme="slate"] {
|
||||
--md-code-hl-string-color: #8b8b8b;
|
||||
--md-code-hl-keyword-color: white;
|
||||
--md-code-hl-number-color: white;
|
||||
--md-typeset-a-color: white;
|
||||
--md-code-hl-keyword-color: #ffe8a3;
|
||||
--md-code-hl-number-color: #ffe8a3;
|
||||
--md-typeset-a-color: #ffe8a3;
|
||||
}
|
||||
|
||||
[data-md-color-scheme="default"] {
|
||||
--md-code-hl-string-color: #444444;
|
||||
--md-code-hl-keyword-color: black;
|
||||
--md-code-hl-number-color: black;
|
||||
--md-code-hl-keyword-color: #bd9100;
|
||||
--md-code-hl-number-color: #bd9100;
|
||||
}
|
||||
|
||||
[data-md-color-scheme=slate][data-md-color-primary=black] {
|
||||
--md-typeset-a-color: white;
|
||||
--md-typeset-a-color: #ffe8a3;
|
||||
}
|
||||
|
||||
[data-md-color-scheme=default][data-md-color-primary=black] {
|
||||
--md-typeset-a-color: black;
|
||||
--md-typeset-a-color: #bd9100;
|
||||
} */
|
||||
|
||||
:root {
|
||||
--md-text-font: "LXGW WenKai";
|
||||
--md-code-font: "LXGW WenKai Mono";
|
||||
}
|
||||
38
mkdocs.yml
@@ -1,5 +1,5 @@
|
||||
site_name: Bioxel Nodes Handbook
|
||||
site_url: https://omoolab.github.io/BioxelNodes/
|
||||
site_name: Bioxel Nodes Docs
|
||||
site_url: https://docs.omoolab.xyz/bioxelnodes/
|
||||
site_author: OmooLab
|
||||
site_description: Bioxel Nodes is a Blender add-on for scientific volumetric data visualization.
|
||||
|
||||
@@ -7,22 +7,21 @@ repo_name: OmooLab/BioxelNodes
|
||||
repo_url: https://github.com/OmooLab/BioxelNodes
|
||||
|
||||
nav:
|
||||
- index.md
|
||||
- Getting Started:
|
||||
- Installation: installation.md
|
||||
- Step by Step: step_by_step.md
|
||||
- Advanced Usage: advanced_usage.md
|
||||
- Support Format: support_format.md
|
||||
- Improve Performance: improve_performance.md
|
||||
- FAQ: faq.md
|
||||
- Tutorials:
|
||||
- SARS-Cov-2: SARS-Cov-2.md
|
||||
- 胞素节点:
|
||||
- index.md
|
||||
- gallery.md
|
||||
- 快速开始:
|
||||
- installation.md
|
||||
- basics.md
|
||||
- advanced.md
|
||||
- dataset.md
|
||||
- performance.md
|
||||
|
||||
theme:
|
||||
name: material
|
||||
favicon: assets/logo.png
|
||||
logo: assets/logo.png
|
||||
language: en
|
||||
language: zh
|
||||
font:
|
||||
text: Open Sans
|
||||
code: Cascadia Code
|
||||
@@ -62,7 +61,6 @@ theme:
|
||||
extra:
|
||||
version:
|
||||
provider: mike
|
||||
default: latest
|
||||
|
||||
extra_css:
|
||||
- stylesheets/extra.css
|
||||
@@ -72,6 +70,18 @@ copyright: Copyright © 2020 - 2024 Omoolab
|
||||
plugins:
|
||||
- search
|
||||
- mkdocstrings
|
||||
- i18n:
|
||||
docs_structure: suffix
|
||||
languages:
|
||||
- locale: zh
|
||||
name: 中文
|
||||
default: true
|
||||
- locale: en
|
||||
name: English
|
||||
nav_translations:
|
||||
胞素节点: Bioxel Nodes
|
||||
快速开始: Getting Started
|
||||
案例教程: Tutorials
|
||||
|
||||
markdown_extensions:
|
||||
- attr_list
|
||||
|
||||
20
openspec/config.yaml
Normal file
@@ -0,0 +1,20 @@
|
||||
schema: spec-driven
|
||||
|
||||
# Project context (optional)
|
||||
# This is shown to AI when creating artifacts.
|
||||
# Add your tech stack, conventions, style guides, domain knowledge, etc.
|
||||
# Example:
|
||||
# context: |
|
||||
# Tech stack: TypeScript, React, Node.js
|
||||
# We use conventional commits
|
||||
# Domain: e-commerce platform
|
||||
|
||||
# Per-artifact rules (optional)
|
||||
# Add custom rules for specific artifacts.
|
||||
# Example:
|
||||
# rules:
|
||||
# proposal:
|
||||
# - Keep proposals under 500 words
|
||||
# - Always include a "Non-goals" section
|
||||
# tasks:
|
||||
# - Break tasks into chunks of max 2 hours
|
||||
92
pack.py
Normal file
@@ -0,0 +1,92 @@
|
||||
"""
|
||||
Create a zip archive of the src/bioxelnodes package with a top-level folder
|
||||
named `bioxelnodes/`. Excludes specified temporary/cache files and folders.
|
||||
Does not modify any files in the project.
|
||||
|
||||
Usage:
|
||||
python build_package.py <platform_name> [output_zip_path]
|
||||
|
||||
Example:
|
||||
python build_package.py windows-x64
|
||||
"""
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import zipfile
|
||||
import fnmatch
|
||||
from datetime import datetime
|
||||
|
||||
platforms = {
|
||||
"windows-x64": "windows-x64",
|
||||
"linux-x64": "linux-x64",
|
||||
"macos-arm64": "macos-arm64",
|
||||
"macos-x64": "macos-x64",
|
||||
}
|
||||
|
||||
# patterns to exclude (filename matching)
|
||||
EXCLUDE_FILENAME_PATTERNS = [
|
||||
"*.blend1",
|
||||
"blendcache_*",
|
||||
"*.cats.txt~",
|
||||
"*.pyc",
|
||||
"*.pyo",
|
||||
"*$py.class",
|
||||
]
|
||||
|
||||
# directory names to exclude entirely
|
||||
EXCLUDE_DIR_NAMES = {
|
||||
"__pycache__",
|
||||
}
|
||||
|
||||
def should_exclude(path: Path) -> bool:
|
||||
name = path.name
|
||||
# exclude directories by name anywhere in the path
|
||||
if any(part in EXCLUDE_DIR_NAMES for part in path.parts):
|
||||
return True
|
||||
# only apply filename patterns to files
|
||||
if path.is_file():
|
||||
for pat in EXCLUDE_FILENAME_PATTERNS:
|
||||
if fnmatch.fnmatch(name, pat):
|
||||
return True
|
||||
return False
|
||||
|
||||
def build_package(platform_name: str, out_zip: Path):
|
||||
src_root = Path("src") / "bioxelnodes"
|
||||
if not src_root.exists():
|
||||
raise SystemExit(f"Source folder not found: {src_root.resolve()}")
|
||||
|
||||
out_zip.parent.mkdir(parents=True, exist_ok=True)
|
||||
total = 0
|
||||
with zipfile.ZipFile(out_zip, "w", compression=zipfile.ZIP_DEFLATED) as zf:
|
||||
for p in src_root.rglob("*"):
|
||||
if p.is_dir():
|
||||
continue
|
||||
if should_exclude(p):
|
||||
continue
|
||||
# arcname should place files under top-level 'bioxelnodes/...'
|
||||
rel = p.relative_to(src_root)
|
||||
arcname = Path("bioxelnodes") / rel
|
||||
zf.write(p, arcname.as_posix())
|
||||
total += 1
|
||||
print(f"Packaged {total} files into {out_zip}")
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python build_package.py <platform_name> [output_zip_path]")
|
||||
print("Available platforms:", ", ".join(platforms.keys()))
|
||||
sys.exit(1)
|
||||
|
||||
platform_key = sys.argv[1]
|
||||
if platform_key not in platforms:
|
||||
print("Unknown platform:", platform_key)
|
||||
print("Available platforms:", ", ".join(platforms.keys()))
|
||||
sys.exit(1)
|
||||
|
||||
tag = platforms[platform_key]
|
||||
timestamp = datetime.now().strftime("%Y%m%dT%H%M%S")
|
||||
default_name = f"bioxelnodes-{tag}-{timestamp}.zip"
|
||||
out_path = Path(sys.argv[2]) if len(sys.argv) >= 3 else Path(default_name)
|
||||
|
||||
build_package(platform_key, out_path)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,8 +1,8 @@
|
||||
[project]
|
||||
name = "bioxelnodes"
|
||||
version = "1.0.9"
|
||||
version = "2.0.4"
|
||||
description = ""
|
||||
authors = [{ name = "Ma Nan", email = "icrdr2010@outlook.com" }]
|
||||
authors = [{ name = "MaNan", email = "icrdr2010@outlook.com" }]
|
||||
requires-python = ">=3.11.0,<3.12.dev0"
|
||||
readme = "README.md"
|
||||
license = "MIT"
|
||||
@@ -12,11 +12,13 @@ dependencies = [
|
||||
"mrcfile==1.5.1",
|
||||
"h5py==3.11.0",
|
||||
"transforms3d==0.4.2",
|
||||
"matplotlib==3.10.7",
|
||||
"scipy==1.16.3",
|
||||
]
|
||||
|
||||
[dependency-groups]
|
||||
dev = [
|
||||
"bpy>=4.2.0,<5",
|
||||
"bpy==5.0.0",
|
||||
"pytest>=8.3.2,<9",
|
||||
"pytest-dependency>=0.6.0,<0.7",
|
||||
"pytest-cov>=5.0.0,<6",
|
||||
@@ -25,6 +27,10 @@ dev = [
|
||||
"autopep8>=2.3.1,<3",
|
||||
"mike>=2.1.2,<3",
|
||||
"tomlkit>=0.13.0,<0.14",
|
||||
"pip>=25.3",
|
||||
"mkdocstrings[python]>=1.0.4",
|
||||
"mkdocs-static-i18n[material]>=1.3.1",
|
||||
"mkdocs-click>=0.9.0",
|
||||
]
|
||||
|
||||
[build-system]
|
||||
|
||||
@@ -1,26 +1,80 @@
|
||||
import bpy
|
||||
import bpy.utils.previews as previews
|
||||
|
||||
from .constants import PREVIEW_COLLECTIONS
|
||||
from .props import _bioxel_layer_items, _update_layer_gallery, _update_snapshot_z
|
||||
|
||||
from .props import BIOXELNODES_LayerListUL
|
||||
from . import auto_load
|
||||
from . import menus
|
||||
|
||||
|
||||
auto_load.init()
|
||||
|
||||
CLI_COMMAND_NAME = "bioxelnodes_import_worker"
|
||||
|
||||
|
||||
def register():
|
||||
pcoll = previews.new()
|
||||
pcoll.layer_previews = ()
|
||||
PREVIEW_COLLECTIONS["layers"] = pcoll
|
||||
|
||||
bpy.types.WindowManager.bioxel_progress_factor = bpy.props.FloatProperty(
|
||||
default=1.0
|
||||
)
|
||||
|
||||
bpy.types.WindowManager.bioxel_progress_text = bpy.props.StringProperty()
|
||||
|
||||
bpy.types.WindowManager.bioxel_layer_library = bpy.props.EnumProperty(
|
||||
name="Bioxel Layer Gallery",
|
||||
items=_bioxel_layer_items,
|
||||
update=_update_layer_gallery,
|
||||
)
|
||||
|
||||
bpy.types.WindowManager.bioxel_snapshot_z = bpy.props.FloatProperty(
|
||||
name="Snapshot Z",
|
||||
default=0.5,
|
||||
min=0.0,
|
||||
max=1.0,
|
||||
subtype="FACTOR",
|
||||
update=_update_snapshot_z,
|
||||
)
|
||||
|
||||
bpy.types.WindowManager.bioxel_layer_list_index = bpy.props.IntProperty(
|
||||
default=0)
|
||||
|
||||
auto_load.register()
|
||||
bpy.types.WindowManager.bioxelnodes_progress_factor = bpy.props.FloatProperty(
|
||||
default=1.0)
|
||||
bpy.types.WindowManager.bioxelnodes_progress_text = bpy.props.StringProperty()
|
||||
bpy.types.WindowManager.bioxelnodes_layer_list_UL = bpy.props.PointerProperty(
|
||||
type=BIOXELNODES_LayerListUL)
|
||||
menus.add()
|
||||
register_cli_commands()
|
||||
|
||||
|
||||
def unregister():
|
||||
unregister_cli_commands()
|
||||
menus.remove()
|
||||
del bpy.types.WindowManager.bioxelnodes_progress_factor
|
||||
del bpy.types.WindowManager.bioxelnodes_progress_text
|
||||
del bpy.types.WindowManager.bioxelnodes_layer_list_UL
|
||||
auto_load.unregister()
|
||||
|
||||
del bpy.types.WindowManager.bioxel_progress_factor
|
||||
del bpy.types.WindowManager.bioxel_progress_text
|
||||
del bpy.types.WindowManager.bioxel_layer_library
|
||||
del bpy.types.WindowManager.bioxel_snapshot_z
|
||||
del bpy.types.WindowManager.bioxel_layer_list_index
|
||||
|
||||
for pcoll in PREVIEW_COLLECTIONS.values():
|
||||
previews.remove(pcoll)
|
||||
PREVIEW_COLLECTIONS.clear()
|
||||
|
||||
|
||||
def import_worker_cli(args):
|
||||
from .operators import io_worker
|
||||
|
||||
return io_worker.main(args)
|
||||
|
||||
|
||||
def register_cli_commands():
|
||||
unregister_cli_commands()
|
||||
bpy.utils.register_cli_command(CLI_COMMAND_NAME, import_worker_cli)
|
||||
|
||||
|
||||
def unregister_cli_commands():
|
||||
try:
|
||||
bpy.utils.unregister_cli_command(CLI_COMMAND_NAME)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
134
src/bioxelnodes/asset_library.py
Normal file
@@ -0,0 +1,134 @@
|
||||
import bpy
|
||||
from pathlib import Path
|
||||
|
||||
from .constants import LATEST_NODE_LIB_PATH, NODE_LIB_DIRPATH, NODE_LIB_FILENAME
|
||||
|
||||
|
||||
ASSET_LIBRARY_NAME = "O Bioxel"
|
||||
ASSET_LIBRARY_READY = "READY"
|
||||
ASSET_LIBRARY_OUTDATED = "OUTDATED"
|
||||
ASSET_LIBRARY_MISSING = "MISSING"
|
||||
|
||||
STATUS_MESSAGES = {
|
||||
"missing": "O Bioxel asset library is not installed.",
|
||||
"missing_blend": "O Bioxel node library file is missing.",
|
||||
"outdated": "O Bioxel node library needs update.",
|
||||
"ready": "O Bioxel asset library is ready.",
|
||||
}
|
||||
|
||||
|
||||
def _asset_library_path():
|
||||
return str(NODE_LIB_DIRPATH)
|
||||
|
||||
|
||||
def _normalized_path(path):
|
||||
return Path(bpy.path.abspath(path)).resolve()
|
||||
|
||||
|
||||
def _asset_libraries():
|
||||
return bpy.context.preferences.filepaths.asset_libraries
|
||||
|
||||
|
||||
def _find_bioxel_asset_library():
|
||||
lib_path = _normalized_path(_asset_library_path())
|
||||
named_lib = None
|
||||
|
||||
for lib in _asset_libraries():
|
||||
try:
|
||||
if _normalized_path(lib.path) == lib_path:
|
||||
return lib
|
||||
if lib.name == ASSET_LIBRARY_NAME:
|
||||
named_lib = lib
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
return named_lib
|
||||
|
||||
|
||||
def _node_lib_path_for_library(lib):
|
||||
return _normalized_path(lib.path) / NODE_LIB_FILENAME
|
||||
|
||||
|
||||
def get_bioxel_asset_library():
|
||||
lib_path = _normalized_path(_asset_library_path())
|
||||
|
||||
for lib in _asset_libraries():
|
||||
try:
|
||||
if _normalized_path(lib.path) == lib_path:
|
||||
return lib
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_bioxel_asset_library_status():
|
||||
lib = _find_bioxel_asset_library()
|
||||
lib_path = _normalized_path(_asset_library_path())
|
||||
|
||||
if lib is None:
|
||||
return {"code": ASSET_LIBRARY_MISSING, "reason": "missing",
|
||||
"message": STATUS_MESSAGES["missing"]}
|
||||
|
||||
try:
|
||||
installed_lib_path = _normalized_path(lib.path)
|
||||
except Exception:
|
||||
return {"code": ASSET_LIBRARY_MISSING, "reason": "missing",
|
||||
"message": STATUS_MESSAGES["missing"]}
|
||||
|
||||
if not _node_lib_path_for_library(lib).is_file():
|
||||
return {"code": ASSET_LIBRARY_MISSING, "reason": "missing_blend",
|
||||
"message": STATUS_MESSAGES["missing_blend"]}
|
||||
|
||||
if installed_lib_path != lib_path:
|
||||
return {"code": ASSET_LIBRARY_OUTDATED, "reason": "outdated",
|
||||
"message": STATUS_MESSAGES["outdated"]}
|
||||
|
||||
return {"code": ASSET_LIBRARY_READY, "reason": "ready",
|
||||
"message": STATUS_MESSAGES["ready"]}
|
||||
|
||||
|
||||
def has_bioxel_asset_library():
|
||||
return get_bioxel_asset_library_status()["code"] in {
|
||||
ASSET_LIBRARY_READY,
|
||||
ASSET_LIBRARY_OUTDATED,
|
||||
}
|
||||
|
||||
|
||||
def add_bioxel_asset_library():
|
||||
if not NODE_LIB_DIRPATH.exists():
|
||||
raise FileNotFoundError(f"Node library path does not exist: {NODE_LIB_DIRPATH}")
|
||||
if not LATEST_NODE_LIB_PATH.is_file():
|
||||
raise FileNotFoundError(f"Node library file does not exist: {LATEST_NODE_LIB_PATH}")
|
||||
|
||||
prefs = _asset_libraries()
|
||||
lib = _find_bioxel_asset_library()
|
||||
|
||||
if lib is None:
|
||||
for item in prefs:
|
||||
try:
|
||||
if item.name == ASSET_LIBRARY_NAME:
|
||||
lib = item
|
||||
break
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
if lib is None:
|
||||
lib = prefs.new()
|
||||
|
||||
lib.name = ASSET_LIBRARY_NAME
|
||||
lib.path = _asset_library_path()
|
||||
lib.import_method = "PACK"
|
||||
return lib
|
||||
|
||||
|
||||
def remove_bioxel_asset_library_if_exists():
|
||||
lib_path = _normalized_path(_asset_library_path())
|
||||
prefs = _asset_libraries()
|
||||
|
||||
for lib in list(prefs):
|
||||
try:
|
||||
if "Bioxel" in lib.name or _normalized_path(lib.path) == lib_path:
|
||||
prefs.remove(lib)
|
||||
except Exception:
|
||||
continue
|
||||
BIN
src/bioxelnodes/assets/O_Bioxel/O_Bioxel_Nodes.blend
LFS
Normal file
12
src/bioxelnodes/assets/O_Bioxel/blender_assets.cats.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
# This is an Asset Catalog Definition file for Blender.
|
||||
#
|
||||
# Empty lines and lines starting with `#` will be ignored.
|
||||
# The first non-ignored line should be the version indicator.
|
||||
# Other lines are of the format "UUID:catalog/path/for/assets:simple catalog name"
|
||||
|
||||
VERSION 1
|
||||
|
||||
c0699a8b-6fd6-4d10-bdde-5ea0fa36724d:O Bioxel:O Bioxel
|
||||
5ea24e10-5a2b-44d1-b67b-19014c412793:O Bioxel/Layer:O Bioxel-Layer
|
||||
17383d65-f1a0-4122-b73a-0baaad4b8ecf:O Bioxel/Structure:O Bioxel-Structure
|
||||
d03fc5b0-465c-45ba-ba8e-524a1c52ae3d:O Bioxel/Utilities:O Bioxel-Utilities
|
||||
@@ -15,6 +15,9 @@ blender_version = bpy.app.version
|
||||
|
||||
modules = None
|
||||
ordered_classes = None
|
||||
SKIP_MODULE_NAMES = {
|
||||
"operators.io_worker",
|
||||
}
|
||||
|
||||
|
||||
def init():
|
||||
@@ -57,6 +60,8 @@ def get_all_submodules(directory):
|
||||
|
||||
def iter_submodules(path, package_name):
|
||||
for name in sorted(iter_submodule_names(path)):
|
||||
if name in SKIP_MODULE_NAMES:
|
||||
continue
|
||||
yield importlib.import_module("." + name, package_name)
|
||||
|
||||
|
||||
@@ -80,11 +85,13 @@ def get_ordered_classes_to_register(modules):
|
||||
|
||||
def get_register_deps_dict(modules):
|
||||
my_classes = set(iter_my_classes(modules))
|
||||
my_classes_by_idname = {cls.bl_idname: cls for cls in my_classes if hasattr(cls, "bl_idname")}
|
||||
my_classes_by_idname = {
|
||||
cls.bl_idname: cls for cls in my_classes if hasattr(cls, "bl_idname")}
|
||||
|
||||
deps_dict = {}
|
||||
for cls in my_classes:
|
||||
deps_dict[cls] = set(iter_my_register_deps(cls, my_classes, my_classes_by_idname))
|
||||
deps_dict[cls] = set(iter_my_register_deps(
|
||||
cls, my_classes, my_classes_by_idname))
|
||||
return deps_dict
|
||||
|
||||
|
||||
@@ -181,7 +188,8 @@ def toposort(deps_dict):
|
||||
sorted_values.add(value)
|
||||
else:
|
||||
unsorted.append(value)
|
||||
deps_dict = {value: deps_dict[value] - sorted_values for value in unsorted}
|
||||
deps_dict = {value: deps_dict[value] -
|
||||
sorted_values for value in unsorted}
|
||||
sorted_list_sub.sort(key=lambda cls: getattr(cls, "bl_order", 0))
|
||||
sorted_list.extend(sorted_list_sub)
|
||||
return sorted_list
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
from .layer import Layer
|
||||
from .container import Container
|
||||
from .io import load_container, save_container
|
||||
from .data import (
|
||||
Data,
|
||||
read,
|
||||
read_meta,
|
||||
calc_layer_shape,
|
||||
calc_layer_size,
|
||||
get_ext,
|
||||
SUPPORT_EXTS,
|
||||
DICOM_EXTS,
|
||||
OME_EXTS,
|
||||
MRC_EXTS,
|
||||
SEQUENCE_EXTS
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
'Layer',
|
||||
'Container',
|
||||
'load_container',
|
||||
'save_container',
|
||||
'Data',
|
||||
'read',
|
||||
'read_meta',
|
||||
'calc_layer_shape',
|
||||
'calc_layer_size',
|
||||
'get_ext',
|
||||
'SUPPORT_EXTS',
|
||||
'DICOM_EXTS',
|
||||
'OME_EXTS',
|
||||
'MRC_EXTS',
|
||||
'SEQUENCE_EXTS'
|
||||
]
|
||||
|
||||
831
src/bioxelnodes/bioxel/data.py
Normal file
@@ -0,0 +1,831 @@
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import Optional, Callable, List
|
||||
import numpy as np
|
||||
import SimpleITK as sitk
|
||||
from pyometiff import OMETIFFReader
|
||||
import mrcfile
|
||||
import transforms3d
|
||||
|
||||
from .layer import Layer
|
||||
|
||||
# 类型定义
|
||||
ProgressCallback = Optional[Callable[[float, str], None]]
|
||||
|
||||
|
||||
SUPPORT_EXTS = [
|
||||
"",
|
||||
".dcm",
|
||||
".DCM",
|
||||
".DICOM",
|
||||
".ima",
|
||||
".IMA",
|
||||
".ome.tiff",
|
||||
".ome.tif",
|
||||
".tif",
|
||||
".TIF",
|
||||
".tiff",
|
||||
".TIFF",
|
||||
".mrc",
|
||||
".mrc.gz",
|
||||
".map",
|
||||
".map.gz",
|
||||
".bmp",
|
||||
".BMP",
|
||||
".png",
|
||||
".PNG",
|
||||
".jpg",
|
||||
".JPG",
|
||||
".jpeg",
|
||||
".JPEG",
|
||||
".PIC",
|
||||
".pic",
|
||||
".gipl",
|
||||
".gipl.gz",
|
||||
".lsm",
|
||||
".LSM",
|
||||
".mnc",
|
||||
".MNC",
|
||||
".mrc",
|
||||
".rec",
|
||||
".mha",
|
||||
".mhd",
|
||||
".hdf",
|
||||
".h4",
|
||||
".hdf4",
|
||||
".he2",
|
||||
".h5",
|
||||
".hdf5",
|
||||
".he5",
|
||||
".nia",
|
||||
".nii",
|
||||
".nii.gz",
|
||||
".hdr",
|
||||
".img",
|
||||
".img.gz",
|
||||
".nrrd",
|
||||
".nhdr",
|
||||
".vtk",
|
||||
".gz",
|
||||
]
|
||||
|
||||
OME_EXTS = [".ome.tiff", ".ome.tif", ".tif", ".TIF", ".tiff", ".TIFF"]
|
||||
|
||||
MRC_EXTS = [".mrc", ".mrc.gz", ".map", ".map.gz"]
|
||||
|
||||
DICOM_EXTS = ["", ".dcm", ".DCM", ".DICOM", ".ima", ".IMA"]
|
||||
|
||||
SEQUENCE_EXTS = [
|
||||
".bmp",
|
||||
".BMP",
|
||||
".jpg",
|
||||
".JPG",
|
||||
".jpeg",
|
||||
".JPEG",
|
||||
".tif",
|
||||
".TIF",
|
||||
".tiff",
|
||||
".TIFF",
|
||||
".png",
|
||||
".PNG",
|
||||
".mrc",
|
||||
]
|
||||
|
||||
|
||||
@dataclass
|
||||
class Data:
|
||||
filepath: str
|
||||
series_id: str
|
||||
_data: Optional[np.ndarray] = field(default=None, repr=False)
|
||||
_meta: Optional[dict] = field(default=None, repr=False)
|
||||
|
||||
@property
|
||||
def data(self) -> np.ndarray:
|
||||
if self._data is None:
|
||||
self.load_data()
|
||||
return self._data
|
||||
|
||||
@property
|
||||
def meta(self) -> dict:
|
||||
if self._meta is None:
|
||||
self.load_meta()
|
||||
return self._meta
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self.meta["name"]
|
||||
|
||||
@property
|
||||
def description(self) -> str:
|
||||
return self.meta["description"]
|
||||
|
||||
@property
|
||||
def shape(self) -> tuple:
|
||||
return (
|
||||
self.meta["frame_count"],
|
||||
*self.meta["xyz_shape"],
|
||||
self.meta["channel_count"],
|
||||
)
|
||||
|
||||
@property
|
||||
def xyz_shape(self) -> tuple:
|
||||
return self.meta["xyz_shape"]
|
||||
|
||||
@property
|
||||
def spacing(self) -> tuple:
|
||||
return self.meta["spacing"]
|
||||
|
||||
@property
|
||||
def affine(self) -> np.ndarray:
|
||||
return self.meta["affine"]
|
||||
|
||||
@property
|
||||
def frame_count(self) -> int:
|
||||
return self.meta["frame_count"]
|
||||
|
||||
@property
|
||||
def channel_count(self) -> int:
|
||||
return self.meta["channel_count"]
|
||||
|
||||
@property
|
||||
def dtype(self) -> np.dtype:
|
||||
return self.meta.get("dtype", np.float32)
|
||||
|
||||
def load_meta(self, progress_callback: ProgressCallback = None):
|
||||
data, meta = self._parse_file(progress_callback)
|
||||
self._meta = meta
|
||||
del data
|
||||
|
||||
def load_data(self, progress_callback: ProgressCallback = None):
|
||||
if not self.is_loaded():
|
||||
data, meta = self._parse_file(progress_callback)
|
||||
self._data = data
|
||||
self._meta = meta
|
||||
|
||||
def is_loaded(self) -> bool:
|
||||
return self._data is not None
|
||||
|
||||
def to_layers(
|
||||
self,
|
||||
kind: str = "scalar",
|
||||
layer_name: str = "",
|
||||
bioxel_size: float = 1.0,
|
||||
smooth: int = 0,
|
||||
remap: bool = False,
|
||||
split_channel: bool = False,
|
||||
frame_source: str = "-1",
|
||||
progress_callback: ProgressCallback = None,
|
||||
) -> List[Layer]:
|
||||
from .layer import Layer
|
||||
|
||||
data = self.data.copy()
|
||||
|
||||
data, layer_shape = self._transform_shape(data, frame_source)
|
||||
|
||||
data = self._preprocess(data, kind, remap)
|
||||
|
||||
mat_scale = transforms3d.zooms.zfdir2aff(bioxel_size)
|
||||
affine = np.dot(self.meta["affine"], mat_scale)
|
||||
|
||||
base_name = layer_name or kind.capitalize()
|
||||
|
||||
if kind == "label":
|
||||
return self._create_label_layers(
|
||||
data, base_name, layer_shape, affine, smooth, progress_callback
|
||||
)
|
||||
elif kind == "color":
|
||||
return self._create_color_layers(
|
||||
data, base_name, layer_shape, affine, progress_callback
|
||||
)
|
||||
elif kind == "scalar":
|
||||
return self._create_scalar_layers(
|
||||
data,
|
||||
base_name,
|
||||
layer_shape,
|
||||
affine,
|
||||
smooth,
|
||||
split_channel,
|
||||
progress_callback,
|
||||
)
|
||||
|
||||
return []
|
||||
|
||||
def _parse_file(self, progress_callback: ProgressCallback = None):
|
||||
data_path = Path(self.filepath).resolve()
|
||||
ext = self._get_ext(data_path)
|
||||
|
||||
if progress_callback:
|
||||
progress_callback(0.0, "Reading Data...")
|
||||
|
||||
is_sequence = False
|
||||
sequence = None
|
||||
if ext in SEQUENCE_EXTS:
|
||||
sequence = self._collect_sequence(data_path)
|
||||
if sequence and len(sequence) > 1:
|
||||
is_sequence = True
|
||||
|
||||
data = None
|
||||
name = ""
|
||||
description = ""
|
||||
affine = np.identity(4)
|
||||
spacing = (1, 1, 1)
|
||||
origin = (0, 0, 0)
|
||||
direction = (1, 0, 0, 0, 1, 0, 0, 0, 1)
|
||||
|
||||
if data is None and ext in MRC_EXTS and not is_sequence:
|
||||
data, name, spacing = self._parse_mrc(data_path)
|
||||
|
||||
if data is None and ext in OME_EXTS and not is_sequence:
|
||||
data, name, spacing = self._parse_ome_tiff(data_path, progress_callback)
|
||||
|
||||
if data is None:
|
||||
data, name, description, spacing, origin, direction = self._parse_sitk(
|
||||
data_path, ext, is_sequence, sequence, progress_callback
|
||||
)
|
||||
|
||||
t = origin
|
||||
r = np.array(direction).reshape((3, 3))
|
||||
affine = np.dot(affine, transforms3d.affines.compose(t, r, [1, 1, 1]))
|
||||
|
||||
meta = {
|
||||
"name": name,
|
||||
"description": description,
|
||||
"spacing": spacing,
|
||||
"affine": affine,
|
||||
"xyz_shape": data.shape[1:4],
|
||||
"frame_count": data.shape[0],
|
||||
"channel_count": data.shape[-1],
|
||||
"dtype": data.dtype,
|
||||
}
|
||||
|
||||
return data, meta
|
||||
|
||||
def _parse_mrc(self, data_path: Path):
|
||||
print("Parsing with mrcfile...")
|
||||
with mrcfile.open(data_path, "r") as mrc:
|
||||
mrc_data = mrc.data
|
||||
|
||||
if mrc.is_single_image():
|
||||
data = np.expand_dims(np.asarray(mrc_data), axis=0)
|
||||
data = np.expand_dims(data, axis=-1)
|
||||
data = np.expand_dims(data, axis=-1)
|
||||
elif mrc.is_image_stack():
|
||||
data = np.expand_dims(np.asarray(mrc_data), axis=-1)
|
||||
data = np.expand_dims(data, axis=-1)
|
||||
elif mrc.is_volume():
|
||||
data = np.expand_dims(np.asarray(mrc_data), axis=0)
|
||||
data = np.expand_dims(data, axis=-1)
|
||||
elif mrc.is_volume_stack():
|
||||
data = np.expand_dims(np.asarray(mrc_data), axis=-1)
|
||||
|
||||
name = self._get_file_no_digits_name(data_path)
|
||||
spacing = (mrc.voxel_size.x, mrc.voxel_size.y, mrc.voxel_size.z)
|
||||
|
||||
return data, name, spacing
|
||||
|
||||
def _parse_ome_tiff(self, data_path: Path, progress_callback=None):
|
||||
print("Parsing with OMETIFFReader...")
|
||||
reader = OMETIFFReader(fpath=data_path)
|
||||
ome_image, metadata, xml_metadata = reader.read()
|
||||
|
||||
if progress_callback:
|
||||
progress_callback(0.5, "Transpose to 'TXYZC'...")
|
||||
|
||||
try:
|
||||
ome_order = metadata["DimOrder BF Array"]
|
||||
data = self._transpose_ome_image(ome_image, ome_order)
|
||||
|
||||
try:
|
||||
spacing = (
|
||||
metadata["PhysicalSizeX"],
|
||||
metadata["PhysicalSizeY"],
|
||||
metadata["PhysicalSizeZ"],
|
||||
)
|
||||
except:
|
||||
spacing = (1, 1, 1)
|
||||
|
||||
name = self._get_file_no_digits_name(data_path)
|
||||
except Exception as e:
|
||||
print(f"Error parsing OME-TIFF: {e}")
|
||||
data = np.zeros((1, 1, 1, 1, 1), dtype=np.float32)
|
||||
name = ""
|
||||
spacing = (1, 1, 1)
|
||||
|
||||
return data, name, spacing
|
||||
|
||||
def _parse_sitk(
|
||||
self,
|
||||
data_path: Path,
|
||||
ext: str,
|
||||
is_sequence: bool,
|
||||
sequence: Optional[list],
|
||||
progress_callback=None,
|
||||
):
|
||||
print("Parsing with SimpleITK...")
|
||||
|
||||
if ext in DICOM_EXTS:
|
||||
data_dirpath = data_path.parent
|
||||
reader = sitk.ImageSeriesReader()
|
||||
reader.MetaDataDictionaryArrayUpdateOn()
|
||||
reader.LoadPrivateTagsOn()
|
||||
series_files = reader.GetGDCMSeriesFileNames(
|
||||
str(data_dirpath), self.series_id
|
||||
)
|
||||
reader.SetFileNames(series_files)
|
||||
|
||||
itk_image = reader.Execute()
|
||||
name, description = self._extract_dicom_meta(reader, data_dirpath)
|
||||
|
||||
elif ext in SEQUENCE_EXTS and is_sequence and sequence:
|
||||
sequence_list = sequence if sequence else []
|
||||
itk_image = sitk.ReadImage(sequence_list)
|
||||
name = self._get_file_no_digits_name(data_path)
|
||||
description = ""
|
||||
|
||||
else:
|
||||
itk_image = sitk.ReadImage(data_path)
|
||||
name = self._get_filename(data_path)
|
||||
description = ""
|
||||
|
||||
if progress_callback:
|
||||
progress_callback(0.5, "Transpose to 'TXYZC'...")
|
||||
|
||||
data = self._convert_sitk_to_numpy(itk_image, ext, is_sequence)
|
||||
|
||||
if itk_image.GetDimension() >= 3 and ext not in SEQUENCE_EXTS:
|
||||
spacing = tuple(itk_image.GetSpacing())
|
||||
origin = tuple(itk_image.GetOrigin())
|
||||
direction = tuple(itk_image.GetDirection())
|
||||
else:
|
||||
spacing = (1, 1, 1)
|
||||
origin = (0, 0, 0)
|
||||
direction = (1, 0, 0, 0, 1, 0, 0, 0, 1)
|
||||
|
||||
return data, name, description, spacing, origin, direction
|
||||
|
||||
def _transpose_ome_image(self, ome_image, ome_order: str):
|
||||
if ome_image.ndim == 2:
|
||||
ome_order = ome_order.replace("T", "").replace("C", "").replace("Z", "")
|
||||
bioxel_order = (ome_order.index("X"), ome_order.index("Y"))
|
||||
data = np.transpose(ome_image, bioxel_order)
|
||||
data = np.expand_dims(data, axis=0)
|
||||
data = np.expand_dims(data, axis=-1)
|
||||
data = np.expand_dims(data, axis=-1)
|
||||
|
||||
elif ome_image.ndim == 3:
|
||||
ome_order = ome_order.replace("T", "").replace("C", "")
|
||||
bioxel_order = (
|
||||
ome_order.index("X"),
|
||||
ome_order.index("Y"),
|
||||
ome_order.index("Z"),
|
||||
)
|
||||
data = np.transpose(ome_image, bioxel_order)
|
||||
data = np.expand_dims(data, axis=0)
|
||||
data = np.expand_dims(data, axis=-1)
|
||||
|
||||
elif ome_image.ndim == 4:
|
||||
ome_order = ome_order.replace("T", "")
|
||||
bioxel_order = (
|
||||
ome_order.index("X"),
|
||||
ome_order.index("Y"),
|
||||
ome_order.index("Z"),
|
||||
ome_order.index("C"),
|
||||
)
|
||||
data = np.transpose(ome_image, bioxel_order)
|
||||
data = np.expand_dims(data, axis=0)
|
||||
|
||||
elif ome_image.ndim == 5:
|
||||
bioxel_order = (
|
||||
ome_order.index("T"),
|
||||
ome_order.index("X"),
|
||||
ome_order.index("Y"),
|
||||
ome_order.index("Z"),
|
||||
ome_order.index("C"),
|
||||
)
|
||||
data = np.transpose(ome_image, bioxel_order)
|
||||
|
||||
return data
|
||||
|
||||
def _convert_sitk_to_numpy(self, itk_image, ext: str, is_sequence: bool):
|
||||
if itk_image.GetDimension() == 2:
|
||||
data = sitk.GetArrayFromImage(itk_image)
|
||||
|
||||
if data.ndim == 3:
|
||||
data = np.transpose(data, (1, 0, 2))
|
||||
data = np.expand_dims(data, axis=-2)
|
||||
else:
|
||||
data = np.transpose(data)
|
||||
data = np.expand_dims(data, axis=-1)
|
||||
data = np.expand_dims(data, axis=-1)
|
||||
|
||||
data = np.expand_dims(data, axis=0)
|
||||
|
||||
elif itk_image.GetDimension() == 3:
|
||||
if ext not in SEQUENCE_EXTS:
|
||||
itk_image = sitk.DICOMOrient(itk_image, "RAS")
|
||||
|
||||
data = sitk.GetArrayFromImage(itk_image)
|
||||
|
||||
if data.ndim == 4:
|
||||
data = np.transpose(data, (2, 1, 0, 3))
|
||||
else:
|
||||
data = np.transpose(data)
|
||||
data = np.expand_dims(data, axis=-1)
|
||||
|
||||
data = np.expand_dims(data, axis=0)
|
||||
|
||||
elif itk_image.GetDimension() == 4:
|
||||
data = sitk.GetArrayFromImage(itk_image)
|
||||
|
||||
if data.ndim == 5:
|
||||
data = np.transpose(data, (0, 3, 2, 1, 4))
|
||||
else:
|
||||
data = np.transpose(data, (0, 3, 2, 1))
|
||||
data = np.expand_dims(data, axis=-1)
|
||||
|
||||
return data
|
||||
|
||||
def _extract_dicom_meta(self, reader, data_dirpath: Path):
|
||||
def get_meta(key):
|
||||
try:
|
||||
string = reader.GetMetaData(0, key).removesuffix(" ")
|
||||
string.encode("utf-8")
|
||||
if string in ["No study description", "No series description", ""]:
|
||||
return None
|
||||
else:
|
||||
return string
|
||||
except:
|
||||
return None
|
||||
|
||||
study_description = get_meta("0008|1030") or data_dirpath.name
|
||||
series_description = get_meta("0008|103e")
|
||||
series_modality = get_meta("0008|0060")
|
||||
|
||||
if series_description and series_modality:
|
||||
description = f"{series_description}-{series_modality}"
|
||||
elif series_description:
|
||||
description = series_description
|
||||
elif series_modality:
|
||||
description = series_modality
|
||||
else:
|
||||
description = ""
|
||||
|
||||
name = study_description.replace(" ", "-")
|
||||
description = description.replace(" ", "-")
|
||||
|
||||
return name, description
|
||||
|
||||
@staticmethod
|
||||
def _get_ext(filepath: Path) -> str:
|
||||
if filepath.name.endswith(".nii.gz"):
|
||||
return ".nii.gz"
|
||||
elif filepath.name.endswith(".img.gz"):
|
||||
return ".img.gz"
|
||||
elif filepath.name.endswith(".gipl.gz"):
|
||||
return ".gipl.gz"
|
||||
elif filepath.name.endswith(".ome.tiff"):
|
||||
return ".ome.tiff"
|
||||
elif filepath.name.endswith(".ome.tif"):
|
||||
return ".ome.tif"
|
||||
elif filepath.name.endswith(".mrc.gz"):
|
||||
return ".mrc.gz"
|
||||
elif filepath.name.endswith(".map.gz"):
|
||||
return ".map.gz"
|
||||
else:
|
||||
suffix = filepath.suffix
|
||||
return "" if len(suffix) > 5 else suffix
|
||||
|
||||
@staticmethod
|
||||
def _get_filename(filepath: Path) -> str:
|
||||
ext = Data._get_ext(filepath)
|
||||
return filepath.name.removesuffix(ext)
|
||||
|
||||
@staticmethod
|
||||
def _get_file_no_digits_name(filepath: Path) -> str:
|
||||
prefix, digits, suffix = Data._get_filename_parts(filepath)
|
||||
prefix = Data._remove_end_str(prefix, "_")
|
||||
prefix = Data._remove_end_str(prefix, ".")
|
||||
prefix = Data._remove_end_str(prefix, "-")
|
||||
prefix = Data._remove_end_str(prefix, " ")
|
||||
return prefix + suffix
|
||||
|
||||
@staticmethod
|
||||
def _get_filename_parts(filepath: Path) -> tuple:
|
||||
def has_digits(s):
|
||||
return any(char.isdigit() for char in s)
|
||||
|
||||
name = Data._get_filename(filepath)
|
||||
parts = name.replace(".", " ").replace("_", " ").split(" ")
|
||||
skip_prefixs = ["CH", "ch", "channel"]
|
||||
number_part = None
|
||||
number_part_i = None
|
||||
|
||||
for i, part in enumerate(parts[::-1]):
|
||||
if has_digits(part):
|
||||
if not any([part.startswith(prefix) for prefix in skip_prefixs]):
|
||||
number_part = part
|
||||
number_part_i = len(parts) - i
|
||||
break
|
||||
|
||||
if number_part is None:
|
||||
return name, "", ""
|
||||
|
||||
prefix_parts = parts[: number_part_i - 1]
|
||||
prefix_parts_count = sum([len(part) + 1 for part in prefix_parts])
|
||||
|
||||
digits = ""
|
||||
suffix = ""
|
||||
|
||||
started = False
|
||||
for char in number_part[::-1]:
|
||||
if char.isdigit():
|
||||
started = True
|
||||
digits += char
|
||||
else:
|
||||
if started:
|
||||
break
|
||||
else:
|
||||
suffix += char
|
||||
|
||||
digits = digits[::-1]
|
||||
|
||||
prefix_parts_count += len(number_part) - len(digits) - len(suffix)
|
||||
|
||||
prefix = name[:prefix_parts_count]
|
||||
suffix = name[prefix_parts_count + len(digits) :]
|
||||
|
||||
return prefix, digits, suffix
|
||||
|
||||
@staticmethod
|
||||
def _get_file_index(filepath: Path) -> int:
|
||||
prefix, digits, suffix = Data._get_filename_parts(filepath)
|
||||
return int(digits) if digits != "" else 0
|
||||
|
||||
@staticmethod
|
||||
def _collect_sequence(filepath: Path):
|
||||
file_dict = {}
|
||||
for f in filepath.parent.iterdir():
|
||||
if (
|
||||
f.is_file()
|
||||
and Data._get_ext(filepath) == Data._get_ext(f)
|
||||
and Data._get_file_no_digits_name(filepath)
|
||||
== Data._get_file_no_digits_name(f)
|
||||
):
|
||||
index = Data._get_file_index(f)
|
||||
file_dict[index] = f
|
||||
|
||||
for key in list(file_dict.keys()):
|
||||
if not file_dict.get(key + 1) and not file_dict.get(key - 1):
|
||||
del file_dict[key]
|
||||
|
||||
file_dict = dict(sorted(file_dict.items()))
|
||||
sequence = [str(f) for f in file_dict.values()]
|
||||
|
||||
if len(sequence) == 0:
|
||||
sequence = [str(filepath)]
|
||||
|
||||
return sequence
|
||||
|
||||
@staticmethod
|
||||
def _remove_end_str(string: str, end: str) -> str:
|
||||
while string.endswith(end) and len(string) > 0:
|
||||
string = string.removesuffix(end)
|
||||
return string
|
||||
|
||||
def _transform_shape(self, data, frame_source: str) -> tuple:
|
||||
orig_shape = self.xyz_shape
|
||||
|
||||
if frame_source == "-1":
|
||||
data = data[0:1, :, :, :, :]
|
||||
new_shape = orig_shape
|
||||
elif frame_source == "0":
|
||||
new_shape = orig_shape
|
||||
elif frame_source == "1":
|
||||
data = data.transpose(1, 0, 2, 3, 4)
|
||||
new_shape = (1, orig_shape[1], orig_shape[2])
|
||||
elif frame_source == "2":
|
||||
data = data.transpose(2, 1, 0, 3, 4)
|
||||
new_shape = (orig_shape[0], 1, orig_shape[2])
|
||||
elif frame_source == "3":
|
||||
data = data.transpose(3, 1, 2, 0, 4)
|
||||
new_shape = (orig_shape[0], orig_shape[1], 1)
|
||||
else:
|
||||
data = data.transpose(4, 1, 2, 3, 0)
|
||||
new_shape = orig_shape
|
||||
|
||||
return data, new_shape
|
||||
|
||||
def _preprocess(self, data, kind: str, remap: bool) -> np.ndarray:
|
||||
if kind == "color":
|
||||
if np.issubdtype(data.dtype, np.uint8):
|
||||
data = np.multiply(data, 1.0 / 256, dtype=np.float32)
|
||||
elif data.dtype.kind in ["u", "i"]:
|
||||
data = data.astype(np.float32)
|
||||
min_val, max_val = data.min(), data.max()
|
||||
if max_val != min_val:
|
||||
data = (data - min_val) / (max_val - min_val)
|
||||
else:
|
||||
data = np.zeros_like(data, dtype=np.float32)
|
||||
else:
|
||||
data = data.astype(np.float32)
|
||||
|
||||
if data.shape[4] == 1:
|
||||
data = np.repeat(data, repeats=3, axis=4)
|
||||
elif data.shape[4] == 2:
|
||||
zeros_shape = list(data.shape[:4]) + [1]
|
||||
zeros = np.zeros(zeros_shape, dtype=np.float32)
|
||||
data = np.concatenate((data, zeros), axis=-1)
|
||||
elif data.shape[4] > 3:
|
||||
data = data[:, :, :, :, :3]
|
||||
|
||||
elif kind == "scalar":
|
||||
if remap:
|
||||
data = data.astype(np.float32)
|
||||
min_val, max_val = data.min(), data.max()
|
||||
if max_val != min_val:
|
||||
data = (data - min_val) / (max_val - min_val)
|
||||
else:
|
||||
data = np.zeros_like(data, dtype=np.float32)
|
||||
|
||||
elif kind == "label":
|
||||
data = data.astype(int)
|
||||
|
||||
return data
|
||||
|
||||
def _create_progress_cb_factory(self, progress_callback):
|
||||
def factory(name, progress, progress_step):
|
||||
def callback(frame, total):
|
||||
if progress_callback:
|
||||
sub_progress = progress + frame * (progress_step / total)
|
||||
progress_callback(
|
||||
sub_progress, f"Processing {name} Frame {frame+1}..."
|
||||
)
|
||||
|
||||
return callback
|
||||
|
||||
return factory
|
||||
|
||||
def _create_label_layers(
|
||||
self,
|
||||
data,
|
||||
base_name,
|
||||
layer_shape,
|
||||
affine,
|
||||
smooth,
|
||||
progress_callback: ProgressCallback,
|
||||
):
|
||||
from .layer import Layer
|
||||
|
||||
layers = []
|
||||
label_count = int(np.max(data))
|
||||
if label_count == 0:
|
||||
return layers
|
||||
|
||||
progress_step = 0.7 / label_count
|
||||
cb_factory = self._create_progress_cb_factory(progress_callback)
|
||||
|
||||
for i in range(label_count):
|
||||
name_i = f"{base_name}_{i+1}"
|
||||
progress = 0.2 + i * progress_step
|
||||
if progress_callback:
|
||||
progress_callback(progress, f"Processing {name_i}...")
|
||||
|
||||
label_data = data == np.full_like(data, i + 1)
|
||||
progress_cb = cb_factory(name_i, progress, progress_step)
|
||||
|
||||
layer = Layer(data=label_data, name=name_i, kind="label")
|
||||
layer.resize(
|
||||
shape=layer_shape, smooth=smooth, progress_callback=progress_cb
|
||||
)
|
||||
layer.affine = affine
|
||||
layers.append(layer)
|
||||
|
||||
return layers
|
||||
|
||||
def _create_color_layers(
|
||||
self, data, base_name, layer_shape, affine, progress_callback: ProgressCallback
|
||||
):
|
||||
from .layer import Layer
|
||||
|
||||
if progress_callback:
|
||||
progress_callback(0.2, f"Processing {base_name}...")
|
||||
|
||||
cb_factory = self._create_progress_cb_factory(progress_callback)
|
||||
progress_cb = cb_factory(base_name, 0.2, 0.7)
|
||||
|
||||
layer = Layer(data=data, name=base_name, kind="color")
|
||||
layer.resize(shape=layer_shape, progress_callback=progress_cb)
|
||||
layer.affine = affine
|
||||
|
||||
return [layer]
|
||||
|
||||
def _create_scalar_layers(
|
||||
self,
|
||||
data,
|
||||
base_name,
|
||||
layer_shape,
|
||||
affine,
|
||||
smooth,
|
||||
split_channel,
|
||||
progress_callback: ProgressCallback,
|
||||
):
|
||||
from .layer import Layer
|
||||
|
||||
layers = []
|
||||
cb_factory = self._create_progress_cb_factory(progress_callback)
|
||||
|
||||
if split_channel:
|
||||
channel_count = data.shape[-1]
|
||||
progress_step = 0.7 / channel_count
|
||||
|
||||
for i in range(channel_count):
|
||||
name_i = f"{base_name}_{i+1}"
|
||||
progress = 0.2 + i * progress_step
|
||||
if progress_callback:
|
||||
progress_callback(progress, f"Processing {name_i}...")
|
||||
|
||||
progress_cb = cb_factory(name_i, progress, progress_step)
|
||||
layer = Layer(
|
||||
data=data[:, :, :, :, i : i + 1], name=name_i, kind="scalar"
|
||||
)
|
||||
layer.resize(
|
||||
shape=layer_shape, smooth=smooth, progress_callback=progress_cb
|
||||
)
|
||||
layer.affine = affine
|
||||
layers.append(layer)
|
||||
else:
|
||||
if progress_callback:
|
||||
progress_callback(0.2, f"Processing {base_name}...")
|
||||
|
||||
progress_cb = cb_factory(base_name, 0.2, 0.7)
|
||||
layer = Layer(data=data, name=base_name, kind="scalar")
|
||||
layer.resize(
|
||||
shape=layer_shape, smooth=smooth, progress_callback=progress_cb
|
||||
)
|
||||
layer.affine = affine
|
||||
layers.append(layer)
|
||||
|
||||
return layers
|
||||
|
||||
|
||||
# 模块级函数签名
|
||||
def read(
|
||||
filepath: str, series_id: str = "", progress_callback: ProgressCallback = None
|
||||
) -> Data:
|
||||
filepath = Path(filepath).resolve()
|
||||
if not filepath.exists():
|
||||
raise FileNotFoundError(f"File not found: {filepath}")
|
||||
|
||||
data_obj = Data(filepath=filepath, series_id=series_id)
|
||||
data_obj.load_data(progress_callback)
|
||||
return data_obj
|
||||
|
||||
|
||||
def read_meta(filepath: str, series_id: str = "") -> Data:
|
||||
data_obj = Data(filepath=filepath, series_id=series_id)
|
||||
data_obj.load_meta()
|
||||
return data_obj
|
||||
|
||||
|
||||
def calc_layer_shape(
|
||||
bioxel_size: float, orig_shape: tuple, orig_spacing: tuple
|
||||
) -> tuple:
|
||||
shape = (
|
||||
int(orig_shape[0] / bioxel_size * orig_spacing[0]),
|
||||
int(orig_shape[1] / bioxel_size * orig_spacing[1]),
|
||||
int(orig_shape[2] / bioxel_size * orig_spacing[2]),
|
||||
)
|
||||
return (
|
||||
shape[0] if shape[0] > 0 else 1,
|
||||
shape[1] if shape[1] > 0 else 1,
|
||||
shape[2] if shape[2] > 0 else 1,
|
||||
)
|
||||
|
||||
|
||||
def calc_layer_size(shape: tuple, bioxel_size: float, scale: float = 1.0) -> tuple:
|
||||
size = (
|
||||
float(shape[0] * bioxel_size * scale),
|
||||
float(shape[1] * bioxel_size * scale),
|
||||
float(shape[2] * bioxel_size * scale),
|
||||
)
|
||||
return size
|
||||
|
||||
|
||||
def get_ext(filepath: Path) -> str:
|
||||
if filepath.name.endswith(".nii.gz"):
|
||||
return ".nii.gz"
|
||||
elif filepath.name.endswith(".img.gz"):
|
||||
return ".img.gz"
|
||||
elif filepath.name.endswith(".gipl.gz"):
|
||||
return ".gipl.gz"
|
||||
elif filepath.name.endswith(".ome.tiff"):
|
||||
return ".ome.tiff"
|
||||
elif filepath.name.endswith(".ome.tif"):
|
||||
return ".ome.tif"
|
||||
elif filepath.name.endswith(".mrc.gz"):
|
||||
return ".mrc.gz"
|
||||
elif filepath.name.endswith(".map.gz"):
|
||||
return ".map.gz"
|
||||
else:
|
||||
suffix = filepath.suffix
|
||||
return "" if len(suffix) > 5 else suffix
|
||||
@@ -1,8 +1,13 @@
|
||||
import copy
|
||||
import numpy as np
|
||||
|
||||
from . import scipy
|
||||
from . import scipy as ndi
|
||||
# 条件导入 openvdb(只在 Blender 环境中存在)
|
||||
try:
|
||||
import openvdb as vdb
|
||||
except ImportError:
|
||||
vdb = None
|
||||
|
||||
from scipy import ndimage as ndi
|
||||
|
||||
# 3rd-party
|
||||
import transforms3d
|
||||
@@ -77,21 +82,17 @@ class Layer():
|
||||
for f in range(self.frame_count):
|
||||
mask_frame = mask[f, :, :, :]
|
||||
if smooth > 0:
|
||||
mask_frame = scipy.median_filter(mask_frame.astype(np.float32),
|
||||
mode="nearest",
|
||||
size=smooth)
|
||||
# mask_frame = scipy.median_filter(
|
||||
# mask_frame.astype(np.float32), size=2)
|
||||
mask_frame = ndi.median_filter(mask_frame.astype(np.float32),
|
||||
mode="nearest",
|
||||
size=smooth)
|
||||
mask_frames += (mask_frame,)
|
||||
elif mask.ndim == 3:
|
||||
for f in range(self.frame_count):
|
||||
mask_frame = mask[:, :, :]
|
||||
if smooth > 0:
|
||||
mask_frame = scipy.median_filter(mask_frame.astype(np.float32),
|
||||
mode="nearest",
|
||||
size=smooth)
|
||||
# mask_frame = scipy.median_filter(
|
||||
# mask_frame.astype(np.float32), size=2)
|
||||
mask_frame = ndi.median_filter(mask_frame.astype(np.float32),
|
||||
mode="nearest",
|
||||
size=smooth)
|
||||
mask_frames += (mask_frame,)
|
||||
else:
|
||||
raise Exception("Mask shape order should be TXYZ or XYZ")
|
||||
@@ -121,9 +122,9 @@ class Layer():
|
||||
|
||||
frame = data[f, :, :, :, :]
|
||||
if smooth > 0:
|
||||
frame = scipy.median_filter(frame.astype(np.float32),
|
||||
mode="nearest",
|
||||
size=smooth)
|
||||
frame = ndi.median_filter(frame.astype(np.float32),
|
||||
mode="nearest",
|
||||
size=smooth)
|
||||
|
||||
factors = np.divide(self.shape, shape)
|
||||
zoom_factors = [1 / f for f in factors]
|
||||
@@ -150,3 +151,32 @@ class Layer():
|
||||
|
||||
mat_scale = transforms3d.zooms.zfdir2aff(factors[0])
|
||||
self.affine = np.dot(self.affine, mat_scale)
|
||||
|
||||
def snapshot(self, shape: tuple, smooth: int = 0):
|
||||
if len(shape) != 3:
|
||||
raise Exception("Shape must be 3 dim")
|
||||
|
||||
data = self.data
|
||||
|
||||
snapshot = data[0, :, :, :, :]
|
||||
|
||||
factors = np.divide(self.shape, shape)
|
||||
zoom_factors = [1 / f for f in factors]
|
||||
order = 0 if snapshot.dtype == bool else 1
|
||||
snapshot = ndi.zoom(snapshot,
|
||||
zoom_factors+[1.0],
|
||||
mode="nearest",
|
||||
grid_mode=False,
|
||||
order=order)
|
||||
|
||||
snapshot = snapshot.astype(np.float32)
|
||||
|
||||
if self.kind in ['scalar', 'vector', 'color']:
|
||||
mn = float(np.nanmin(snapshot))
|
||||
mx = float(np.nanmax(snapshot))
|
||||
if mx - mn > 1e-8:
|
||||
snapshot = (snapshot - mn) / (mx - mn)
|
||||
else:
|
||||
snapshot = np.clip(snapshot, 0.0, 1.0)
|
||||
|
||||
return snapshot
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
from ._interpolation import zoom
|
||||
from ._filters import (gaussian_filter,
|
||||
median_filter,
|
||||
maximum_filter,
|
||||
minimum_filter)
|
||||
@@ -1,313 +0,0 @@
|
||||
import numpy as np
|
||||
import warnings
|
||||
|
||||
from . import _ni_support
|
||||
from . import _nd_image
|
||||
from ._utils import normalize_axis_index
|
||||
|
||||
|
||||
def _prepad_for_spline_filter(input, mode, cval):
|
||||
if mode in ['nearest', 'grid-constant']:
|
||||
npad = 12
|
||||
if mode == 'grid-constant':
|
||||
padded = np.pad(input, npad, mode='constant',
|
||||
constant_values=cval)
|
||||
elif mode == 'nearest':
|
||||
padded = np.pad(input, npad, mode='edge')
|
||||
else:
|
||||
# other modes have exact boundary conditions implemented so
|
||||
# no prepadding is needed
|
||||
npad = 0
|
||||
padded = input
|
||||
return padded, npad
|
||||
|
||||
def spline_filter1d(input, order=3, axis=-1, output=np.float64,
|
||||
mode='mirror'):
|
||||
"""
|
||||
Calculate a 1-D spline filter along the given axis.
|
||||
|
||||
The lines of the array along the given axis are filtered by a
|
||||
spline filter. The order of the spline must be >= 2 and <= 5.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
%(input)s
|
||||
order : int, optional
|
||||
The order of the spline, default is 3.
|
||||
axis : int, optional
|
||||
The axis along which the spline filter is applied. Default is the last
|
||||
axis.
|
||||
output : ndarray or dtype, optional
|
||||
The array in which to place the output, or the dtype of the returned
|
||||
array. Default is ``numpy.float64``.
|
||||
%(mode_interp_mirror)s
|
||||
|
||||
Returns
|
||||
-------
|
||||
spline_filter1d : ndarray
|
||||
The filtered input.
|
||||
|
||||
See Also
|
||||
--------
|
||||
spline_filter : Multidimensional spline filter.
|
||||
|
||||
Notes
|
||||
-----
|
||||
All of the interpolation functions in `ndimage` do spline interpolation of
|
||||
the input image. If using B-splines of `order > 1`, the input image
|
||||
values have to be converted to B-spline coefficients first, which is
|
||||
done by applying this 1-D filter sequentially along all
|
||||
axes of the input. All functions that require B-spline coefficients
|
||||
will automatically filter their inputs, a behavior controllable with
|
||||
the `prefilter` keyword argument. For functions that accept a `mode`
|
||||
parameter, the result will only be correct if it matches the `mode`
|
||||
used when filtering.
|
||||
|
||||
For complex-valued `input`, this function processes the real and imaginary
|
||||
components independently.
|
||||
|
||||
.. versionadded:: 1.6.0
|
||||
Complex-valued support added.
|
||||
|
||||
Examples
|
||||
--------
|
||||
We can filter an image using 1-D spline along the given axis:
|
||||
|
||||
>>> from scipy.ndimage import spline_filter1d
|
||||
>>> import numpy as np
|
||||
>>> import matplotlib.pyplot as plt
|
||||
>>> orig_img = np.eye(20) # create an image
|
||||
>>> orig_img[10, :] = 1.0
|
||||
>>> sp_filter_axis_0 = spline_filter1d(orig_img, axis=0)
|
||||
>>> sp_filter_axis_1 = spline_filter1d(orig_img, axis=1)
|
||||
>>> f, ax = plt.subplots(1, 3, sharex=True)
|
||||
>>> for ind, data in enumerate([[orig_img, "original image"],
|
||||
... [sp_filter_axis_0, "spline filter (axis=0)"],
|
||||
... [sp_filter_axis_1, "spline filter (axis=1)"]]):
|
||||
... ax[ind].imshow(data[0], cmap='gray_r')
|
||||
... ax[ind].set_title(data[1])
|
||||
>>> plt.tight_layout()
|
||||
>>> plt.show()
|
||||
|
||||
"""
|
||||
if order < 0 or order > 5:
|
||||
raise RuntimeError('spline order not supported')
|
||||
input = np.asarray(input)
|
||||
complex_output = np.iscomplexobj(input)
|
||||
output = _ni_support._get_output(output, input,
|
||||
complex_output=complex_output)
|
||||
if complex_output:
|
||||
spline_filter1d(input.real, order, axis, output.real, mode)
|
||||
spline_filter1d(input.imag, order, axis, output.imag, mode)
|
||||
return output
|
||||
if order in [0, 1]:
|
||||
output[...] = np.array(input)
|
||||
else:
|
||||
mode = _ni_support._extend_mode_to_code(mode)
|
||||
axis = normalize_axis_index(axis, input.ndim)
|
||||
_nd_image.spline_filter1d(input, order, axis, output, mode)
|
||||
return output
|
||||
|
||||
|
||||
def spline_filter(input, order=3, output=np.float64, mode='mirror'):
|
||||
"""
|
||||
Multidimensional spline filter.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
%(input)s
|
||||
order : int, optional
|
||||
The order of the spline, default is 3.
|
||||
output : ndarray or dtype, optional
|
||||
The array in which to place the output, or the dtype of the returned
|
||||
array. Default is ``numpy.float64``.
|
||||
%(mode_interp_mirror)s
|
||||
|
||||
Returns
|
||||
-------
|
||||
spline_filter : ndarray
|
||||
Filtered array. Has the same shape as `input`.
|
||||
|
||||
See Also
|
||||
--------
|
||||
spline_filter1d : Calculate a 1-D spline filter along the given axis.
|
||||
|
||||
Notes
|
||||
-----
|
||||
The multidimensional filter is implemented as a sequence of
|
||||
1-D spline filters. The intermediate arrays are stored
|
||||
in the same data type as the output. Therefore, for output types
|
||||
with a limited precision, the results may be imprecise because
|
||||
intermediate results may be stored with insufficient precision.
|
||||
|
||||
For complex-valued `input`, this function processes the real and imaginary
|
||||
components independently.
|
||||
|
||||
.. versionadded:: 1.6.0
|
||||
Complex-valued support added.
|
||||
|
||||
Examples
|
||||
--------
|
||||
We can filter an image using multidimentional splines:
|
||||
|
||||
>>> from scipy.ndimage import spline_filter
|
||||
>>> import numpy as np
|
||||
>>> import matplotlib.pyplot as plt
|
||||
>>> orig_img = np.eye(20) # create an image
|
||||
>>> orig_img[10, :] = 1.0
|
||||
>>> sp_filter = spline_filter(orig_img, order=3)
|
||||
>>> f, ax = plt.subplots(1, 2, sharex=True)
|
||||
>>> for ind, data in enumerate([[orig_img, "original image"],
|
||||
... [sp_filter, "spline filter"]]):
|
||||
... ax[ind].imshow(data[0], cmap='gray_r')
|
||||
... ax[ind].set_title(data[1])
|
||||
>>> plt.tight_layout()
|
||||
>>> plt.show()
|
||||
|
||||
"""
|
||||
if order < 2 or order > 5:
|
||||
raise RuntimeError('spline order not supported')
|
||||
input = np.asarray(input)
|
||||
complex_output = np.iscomplexobj(input)
|
||||
output = _ni_support._get_output(output, input,
|
||||
complex_output=complex_output)
|
||||
if complex_output:
|
||||
spline_filter(input.real, order, output.real, mode)
|
||||
spline_filter(input.imag, order, output.imag, mode)
|
||||
return output
|
||||
if order not in [0, 1] and input.ndim > 0:
|
||||
for axis in range(input.ndim):
|
||||
spline_filter1d(input, order, axis, output=output, mode=mode)
|
||||
input = output
|
||||
else:
|
||||
output[...] = input[...]
|
||||
return output
|
||||
|
||||
|
||||
def zoom(input, zoom, output=None, order=3, mode='constant', cval=0.0,
|
||||
prefilter=True, *, grid_mode=False):
|
||||
"""
|
||||
Zoom an array.
|
||||
|
||||
The array is zoomed using spline interpolation of the requested order.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
%(input)s
|
||||
zoom : float or sequence
|
||||
The zoom factor along the axes. If a float, `zoom` is the same for each
|
||||
axis. If a sequence, `zoom` should contain one value for each axis.
|
||||
%(output)s
|
||||
order : int, optional
|
||||
The order of the spline interpolation, default is 3.
|
||||
The order has to be in the range 0-5.
|
||||
%(mode_interp_constant)s
|
||||
%(cval)s
|
||||
%(prefilter)s
|
||||
grid_mode : bool, optional
|
||||
If False, the distance from the pixel centers is zoomed. Otherwise, the
|
||||
distance including the full pixel extent is used. For example, a 1d
|
||||
signal of length 5 is considered to have length 4 when `grid_mode` is
|
||||
False, but length 5 when `grid_mode` is True. See the following
|
||||
visual illustration:
|
||||
|
||||
.. code-block:: text
|
||||
|
||||
| pixel 1 | pixel 2 | pixel 3 | pixel 4 | pixel 5 |
|
||||
|<-------------------------------------->|
|
||||
vs.
|
||||
|<----------------------------------------------->|
|
||||
|
||||
The starting point of the arrow in the diagram above corresponds to
|
||||
coordinate location 0 in each mode.
|
||||
|
||||
Returns
|
||||
-------
|
||||
zoom : ndarray
|
||||
The zoomed input.
|
||||
|
||||
Notes
|
||||
-----
|
||||
For complex-valued `input`, this function zooms the real and imaginary
|
||||
components independently.
|
||||
|
||||
.. versionadded:: 1.6.0
|
||||
Complex-valued support added.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from scipy import ndimage, datasets
|
||||
>>> import matplotlib.pyplot as plt
|
||||
|
||||
>>> fig = plt.figure()
|
||||
>>> ax1 = fig.add_subplot(121) # left side
|
||||
>>> ax2 = fig.add_subplot(122) # right side
|
||||
>>> ascent = datasets.ascent()
|
||||
>>> result = ndimage.zoom(ascent, 3.0)
|
||||
>>> ax1.imshow(ascent, vmin=0, vmax=255)
|
||||
>>> ax2.imshow(result, vmin=0, vmax=255)
|
||||
>>> plt.show()
|
||||
|
||||
>>> print(ascent.shape)
|
||||
(512, 512)
|
||||
|
||||
>>> print(result.shape)
|
||||
(1536, 1536)
|
||||
"""
|
||||
if order < 0 or order > 5:
|
||||
raise RuntimeError('spline order not supported')
|
||||
input = np.asarray(input)
|
||||
if input.ndim < 1:
|
||||
raise RuntimeError('input and output rank must be > 0')
|
||||
zoom = _ni_support._normalize_sequence(zoom, input.ndim)
|
||||
output_shape = tuple(
|
||||
[int(round(ii * jj)) for ii, jj in zip(input.shape, zoom)])
|
||||
complex_output = np.iscomplexobj(input)
|
||||
output = _ni_support._get_output(output, input, shape=output_shape,
|
||||
complex_output=complex_output)
|
||||
if complex_output:
|
||||
# import under different name to avoid confusion with zoom parameter
|
||||
from scipy.ndimage._interpolation import zoom as _zoom
|
||||
|
||||
kwargs = dict(order=order, mode=mode, prefilter=prefilter)
|
||||
_zoom(input.real, zoom, output=output.real,
|
||||
cval=np.real(cval), **kwargs)
|
||||
_zoom(input.imag, zoom, output=output.imag,
|
||||
cval=np.imag(cval), **kwargs)
|
||||
return output
|
||||
if prefilter and order > 1:
|
||||
padded, npad = _prepad_for_spline_filter(input, mode, cval)
|
||||
filtered = spline_filter(padded, order, output=np.float64, mode=mode)
|
||||
else:
|
||||
npad = 0
|
||||
filtered = input
|
||||
if grid_mode:
|
||||
# warn about modes that may have surprising behavior
|
||||
suggest_mode = None
|
||||
if mode == 'constant':
|
||||
suggest_mode = 'grid-constant'
|
||||
elif mode == 'wrap':
|
||||
suggest_mode = 'grid-wrap'
|
||||
if suggest_mode is not None:
|
||||
warnings.warn(
|
||||
(f"It is recommended to use mode = {suggest_mode} instead of {mode} "
|
||||
f"when grid_mode is True."),
|
||||
stacklevel=2
|
||||
)
|
||||
mode = _ni_support._extend_mode_to_code(mode)
|
||||
|
||||
zoom_div = np.array(output_shape)
|
||||
zoom_nominator = np.array(input.shape)
|
||||
if not grid_mode:
|
||||
zoom_div -= 1
|
||||
zoom_nominator -= 1
|
||||
|
||||
# Zooming to infinite values is unpredictable, so just choose
|
||||
# zoom factor 1 instead
|
||||
zoom = np.divide(zoom_nominator, zoom_div,
|
||||
out=np.ones_like(input.shape, dtype=np.float64),
|
||||
where=zoom_div != 0)
|
||||
zoom = np.ascontiguousarray(zoom)
|
||||
_nd_image.zoom_shift(filtered, zoom, None, output, order, mode, cval, npad,
|
||||
grid_mode)
|
||||
return output
|
||||